Concatenate several fields into one with SQL

后端 未结 6 1790
再見小時候
再見小時候 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:27

    As far as I'm aware SQL92 doesn't define how string concatenation should be done. This means that most engines have their own method.

    If you want a database independent method, you'll have to do it outside of the database.

    (untested in all but Oracle)

    Oracle

    SELECT field1 | ', ' | field2
    FROM table;
    

    MS SQL

    SELECT field1 + ', ' + field2
    FROM table;
    

    MySQL

    SELECT concat(field1,', ',field2)
    FROM table;
    

    PostgeSQL

    SELECT field1 || ', ' || field2
    FROM table;
    

提交回复
热议问题