Today I was wondering how can I concatenate multiple rows in a single row. Suppose, I need to get the email addresses of a user table. The “SELECT `email` FROM `usertable`;” will return something like this:
But I needed:
email1, email2, email3
It is very easy to process and make same output using PHP. But I thought there must be a way in MySQL. After searching a while I got the solution. Its simple.
SELECT group_concat(`email`) from `usertable`;
Thats it. Now I got what I wanted :).