concatenate two database columns into one resultset column

后端 未结 7 2179
独厮守ぢ
独厮守ぢ 2020-11-28 10:00

I use the following SQL to concatenate several database columns from one table into one column in the result set:

SELECT (field1 + \'\' + field2 + \'\' + field

7条回答
  •  一生所求
    2020-11-28 10:21

    The SQL standard way of doing this would be:

    SELECT COALESCE(field1, '') || COALESCE(field2, '') || COALESCE(field3, '') FROM table1
    

    Example:

    INSERT INTO table1 VALUES ('hello', null, 'world');
    SELECT COALESCE(field1, '') || COALESCE(field2, '') || COALESCE(field3, '') FROM table1;
    
    helloworld
    

提交回复
热议问题