'SQL to return all the rows of a table as a single string [duplicate]
I'm using MySQL, and I have a table with 3 records:
id, name
1, bill
2, joe
3, sam
I'm looking for a single SQL statement that will return all the ids as a CSV string:
'1,2,3'
This gives me multiple records:
select id from tablename
I'm thinking that I need to use version of the concat function in MySQL, but it's not clear what.
select concat(id) from tablename
But this returns the same as the original (multiple records). Is there an easy way to "collapse" the records to a single row?
Please note that I just need a single string of the "id" column values, not any other columns.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
