1

I have a table like this:

Product_ID | Size_ID
         3 |      S
         3 |      M
         4 |      L
         5 |      S

And I would like the result to be like:

Product_ID | Size_ID
         3 |   M, S
         4 |      L
         5 |      S

Is it possible to do that? My query is this:

Select Product_ID, Size_ID
FROM product
Group by Product_ID
Order by Product_ID Desc
Mureinik
  • 297,002
  • 52
  • 306
  • 350
Ab Le
  • 65
  • 1
  • 1
  • 7
  • GROUP BY is typically used together with aggregate functions, like SUM, COUNT, MAX etc. I think MySQL supports the non-standard group_concat function. – jarlh Jan 09 '15 at 08:50

2 Answers2

1

Try group_concat:

Select Product_ID, GROUP_CONCAT(Size_ID)
FROM product
Group by Product_ID
Order by Product_ID 
Jens
  • 67,715
  • 15
  • 98
  • 113
1

The group_concat function should do the trick:

Select   Product_ID, GROUP_CONCAT(Size_ID ORDER BY Size_ID)
FROM     product
Group by Product_ID
Order by Product_ID Desc
Mureinik
  • 297,002
  • 52
  • 306
  • 350