How to use Coalesce in MySQL

前端 未结 4 1636
梦如初夏
梦如初夏 2020-12-13 18:05

A little help here. I really don\'t understand how to use this coalesce in MySQL

I have read all the pages in page 1 result of how to use coalsece in go

4条回答
  •  难免孤独
    2020-12-13 18:30

    COALESCE will return the first non-null column or value.

    Example Usage:

    SELECT COALESCE(my_column, my_other_column, 'default') as username FROM my_table;
    

    Example results:

    my_column  my_other_column     results
    null       null                'default'
    null       0                   '0'
    null       'jimmy'             'jimmy'
    'bob'      'jimmy'             'bob'
    

提交回复
热议问题