GROUP_CONCAT() function is used to concatenate column values into a single string.
Example:
Table ‘abc’ has following columns:
id customer_id
3 14
3 15
3 16
4 18
4 18
You can use this query:
SELECT id,GROUP_CONCAT(customer_id) FROM abc WHERE id = 3 GROUP BY id;
output:
id customer_id
3 14,15,16
It is useful when you want PHP array without looping inside PHP:

hey dharmesh,
This is a good mysql function for concating the rows.
I have a small doubt on your query you have mentioned above
SELECT id,GROUP_CONCAT(customer_id) FROM abc WHERE id = 3 GROUP BY id;
Here in the query you are giving where clause on id which will bring rows having id =3. Then is there any need of giving GROUP BY clause??????
OR for using GROUP_CONCAT function GROUP BY clause is necesssary?????
Thanx jimit,
Well the use of where clause is optional,depending on your requirements.
when you are wrting only GROUP BY clause, then you will get the following output :
id customer_id
3 14,15,16
4 17,18
5 19,20 and so on
but if you want a specific row then you have to use WHERE clause.
the above query was:
select id, GROUP_CONCAT(customer_id) FROM abc GROUP BY id
It is not necessary to use group by clause always with group_concat.