开发者

MySQL:How to show data from 1 column which separated by comma?

开发者 https://www.devze.com 2023-02-23 13:53 出处:网络
Dear all, i want to show some data in one row from 1 column and also 开发者_Go百科separated by comma.

Dear all, i want to show some data in one row from 1 column and also 开发者_Go百科separated by comma. if I do the regular SELECT method, it must be show as the long rows.

SELECT Serial_number FROM data

+-------------+
|Serial_number|
+-------------+
|0001         |
|0002         |
|0003         |
+-------------+ //and so on

How do i do to show result as:

+------------------------------+
|Serial_number                 |
+------------------------------+
|0001,0002,0003,....and so on  |
+------------------------------+

thanks for advance.


You can use GROUP_CONCAT

SELECT GROUP_CONCAT(Serial_number ) FROM data;

Note: GROUP_CONCAT has a maximum length.


select concat(col1, ',' , col2, .....) from tbl;


i think you can use something like phpmyadmin and save a select statement to file, then select csv as the file type..


what you want is GROUP_CONCAT()

SELECT GROUP_CONCAT(Serial_number) FROM data

yields:

0001,0002,0003,...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号