List:General Discussion« Previous MessageNext Message »
From:Andrew Braithwaite Date:October 11 2006 1:32pm
Subject:Group by and concatenate
View as plain text  
Hi,

I have the following data:

mysql> select Dealername,pc from ford_gb where pc='LE4 7SL';

+-----------------------------+---------+
| Dealername                  | pc      |
+-----------------------------+---------+
| CD Bramall Ford - Leicester | LE4 7SL |
| CD Bramall Ford - Leicester | LE4 7SL |
| CD Bramall Ford - Leicester | LE4 7SL |
+-----------------------------+---------+

Is there a way in a single SQL query to group by Dealername, and have
the postcodes concatenated into a comma-separated list? e.g.

+-----------------------------+----------------------------+
| Dealername                  | concat_pc                  |
+-----------------------------+----------------------------+
| CD Bramall Ford - Leicester | LE4 7SL, LE4 7SL, LE4 7SL  |
+-----------------------------+----------------------------+

Running MySQL 4.1 on Fedora C3.

Any help appreciated,

Andrew
SQL, Query
Thread
Group by and concatenateAndrew Braithwaite11 Oct
  • Re: Group by and concatenateDan Buettner11 Oct
RE: Group by and concatenateAndrew Braithwaite11 Oct