Concatenate several fields into one with SQL

后端 未结 6 1778
再見小時候
再見小時候 2021-02-10 09:54

I have three tables tag, page, pagetag

With the data below

page

ID      NAME
1           


        
6条回答
  •  余生分开走
    2021-02-10 10:42

    pagetag.id and group_concat(tag.name) will be null for page 4 in the example you've posted above, but the page shall appear in the results.

    You can use the COALESCE function to remove the Nulls if you need to:

    select COALESCE(pagetag.id, '') AS id ...
    

    It will return the first non-null value from it's list of parameters.

提交回复
热议问题