|
|||||||
| General Questions Questions that don't fit elsewhere |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Zenner
Join Date: Dec 2005
Posts: 55
|
I am running MySQL 5 and have a SQL query question...
I have a table with data and structure like this: Col_1 Col_2 1 black 2 red 2 blue 2 pink 3 white 3 purple 3 gray 3 peach 4 orange 5 off white 5 gold I'd like to concatenate the rows by id and separate Col_2 with commas for a result like this. Col_1 Col_2 1 black 2 red, blue, pink 3 white, purple, gray, peach 4 orange 5 off white, gold Can someone help me with the query or function to make this happen? Thanks, Angel |
|
|
|
|
|
#2 |
|
New Zenner
Join Date: Dec 2005
Posts: 55
|
I figured this out on my own. It can be done like this:
SELECT b, GROUP_CONCAT(DISTINCT a ORDER BY a DESC SEPARATOR ', ') FROM table_name GROUP BY b; |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|