How to combine multiple columns as one and format with custom strings?

前端 未结 4 1051
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 16:21
SELECT id,  AS name FROM `table`

Basically is a combination of
lastname + \', \' + firstname

example wo

4条回答
  •  死守一世寂寞
    2020-12-14 16:28

    You can use GROUP_CONCAT():

    Example of getting all the column names of a table separated by comma:

    SELECT GROUP_CONCAT(c.`COLUMN_NAME`) FROM information_schema.`COLUMNS` c
    WHERE c.`TABLE_SCHEMA` = "DB_NAME" AND c.`TABLE_NAME`="TABLE_NAME"
    

    Output:

    column_name_1,column_name_2,column_name_3,column_name_4,...
    

提交回复
热议问题