This is a discussion on Group by and concatenate within the MySQL General forum forums, part of the MySQL category; --> Hi, I have the following data: mysql> select Dealername,pc from ford_gb where pc='LE4 7SL'; +-----------------------------+---------+ | Dealername | pc ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| ||||
| Andrew, very possible, have a look at the GROUP_CONCAT function: http://dev.mysql.com/doc/refman/5.0/...functions.html Dan On 10/11/06, Andrew Braithwaite <Andrew@multimap.com> wrote: > 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 Tools | |
| Display Modes | |
|
|