简体   繁体   中英

Get mysql result of multiple rows in one with group_concat

I have a table which has a column id and a column isadmin .

I want to execute this query, which works just fine:

SELECT id FROM mytable WHERE isadmin = TRUE;

But instead of getting multiple rows I would like to get one row in csv format. I found this link and created the following query, which does not work, I get a MySQL error:

SELECT GROUP_CONCAT(id SEPERATOR ',') FROM mytable WHERE isadmin = TRUE;

The error message is:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SEPERATOR ', ') FROM mytable WHERE isadmin = TRUE' at line 1

If this is not enough information just tell me and I will provide them.

The comma is the defaul separator so you don't need

 SELECT GROUP_CONCAT(id ) FROM mytable WHERE isadmin = TRUE;

anyway is separator and nt seperator

SELECT GROUP_CONCAT(id SEPARATOR ',') FROM mytable WHERE isadmin = TRUE;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM