-1

I have a database table with the following data:

+--------------------+-----------------------------+  
|    order_no        |   part                      |   
+--------------------+-----------------------------+  
| AAAAAAAAAAAAA      |  QQQQQQQQ-WWW               |  
| AAAAAAAAAAAAA      |  EEEEEEEE-TTT               |  
| BBBBBBBBBBBBB      |  33333333-333               |  
| BBBBBBBBBBBBB      |  44444444-444               |  
| BBBBBBBBBBBBB      |  EEEEEEEE-TTT               |  
+--------------------+-----------------------------+

My problem is that I can't make a query to produce this result:

+----------------+-------------------------------------------+
|    order_no    |   part                                    |
+----------------+-------------------------------------------+
| AAAAAAAAAAAAA  |  QQQQQQQQ-WWW, EEEEEEEE-TTT               |  
| BBBBBBBBBBBBB  |  33333333-333, 44444444-444, EEEEEEEE-TTT |  
+----------------+-------------------------------------------+  

Thanks in advance.

Paul Brinkley
  • 6,283
  • 3
  • 24
  • 33
  • You are looking for http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat – phobia82 Nov 23 '16 at 19:18

2 Answers2

0

The group_concat aggregate function is just what the doctor ordered:

SELECT   order_no, GROUP_CONCAT(part SEPARATOR ', ')
FROM     mytable
GROUP BY order_no
Mureinik
  • 297,002
  • 52
  • 306
  • 350
-1

Try this:

SELECT order_no, GROUP_CONCAT(string SEPARATOR ', ') FROM table GROUP BY order_no;