Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2005

    Unanswered: Child rows concat


    I was wondering if this is possible in MySQL 4.1.

    I have 2 tables: Category, Products.
    Each product links to a category using a foreign key.

    I want to produce a query that will return the Catagory name in one column and all the product names under that category seperated by commas in the second column.

    So, if Category1 has 4 products and Category2 has 2 products the output would be:
    Category      | Products
    CategoryName1 | ProductName1, ProductName2, ProductName3, ProductName4
    CategoryName2 | ProductName5, ProductName6
    I tried playing around with CONCAT_WS and a GROUP BY on CategoryID but I think I have to have a subquery to pull out the product records for each category because the inner join method doesn't give me the right result.


  2. #2
    Join Date
    Jun 2005
    After a day of searching, I've managed to find the solution.
    MySQL has a function called GROUP_CONCAT that does just what I want.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts