Concat multiple rows!

Wednesday October 29thTutorial Category

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:

email1

email2

email3

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 :).

Bookmark: bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Related Posts:

1 Trackbacks/Pingbacks

  1. Pingback: Concat multiple rows! | lowerautoinsurance on October 29, 2008

1 Comments

  1. Jobaer Shuman
    November 13, 2008

    Thanks for share. :)

Leave a comment

Size

Colors