select query into list on one column

自作多情 提交于 2020-01-07 05:43:26

问题


I am trying to select all id into one column and delimit it with a comma ,

My DATA column:

+---+--------+--------------+
|id |somedata|someother data|
+---+--------+--------------+
|1  |data1   |other1        |
+---+--------+--------------+
|2  |data2   |other2        |
+---+--------+--------------+
|3  |data3   |other3        |
+---+--------+--------------+

The result I am trying to make:

+-------+
|id list|
+-------+
|1, 2, 3|
+-------+

The result should be a list of ID's in 1 column named 'id list'.

The question is, is this possible? and how? I tried searching for the keywords sql query select into list and other keywords but with no luck.


But this query is on a nested select.


回答1:


Use GROUP_CONCAT():

SELECT GROUP_CONCAT(id) AS idList FROM tableA


来源:https://stackoverflow.com/questions/21084354/select-query-into-list-on-one-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!