Skip to content
Advertisement

How to join SQL column elements together?

I have an SQL table with the column named expenses like this

enter image description here

I want to write a query to return all the elements of this column separated by a comma. For the above example output should be:-

hotel,taxi,food,movie

How can I do this?

Advertisement

Answer

You can use the group_concat aggregate function:

SELECT GROUP_CONCAT(expenses)
FROM   my_table
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement