I have a table with rows of data and need to create a comma delimited string for all the rows for a column. Can this be achieved just using the the SELECT statement in SQLite or I have to get the data into Cursor and build the string by iterating through it?
For Example:
UserId
1df4181d-6c52-4aa3-926f-2dacb0a68c70
1df4181d-6c52-4aa3-926f-2dacb0a68c71
1df4181d-6c52-4aa3-926f-2dacb0a68c72
1df4181d-6c52-4aa3-926f-2dacb0a68c73
1df4181d-6c52-4aa3-926f-2dacb0a68c74
1df4181d-6c52-4aa3-926f-2dacb0a68c75
into
1df4181d-6c52-4aa3-926f-2dacb0a68c70,1df4181d-6c52-4aa3-926f-2dacb0a68c71,1df4181d-6c52-4aa3-926f-2dacb0a68c72,1df4181d-6c52-4aa3-926f-2dacb0a68c73,1df4181d-6c52-4aa3-926f-2dacb0a68c74,1df4181d-6c52-4aa3-926f-2dacb0a68c75
Any suggestions would be greatly appreciated.
You can use GROUP_CONCAT()
:
select group_concat(yourColumn, ',')
from yourtable
See SQL Fiddle with Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With