Monday, 24 December 2018

MySQL Function: GROUP_CONCAT

Don’t know why I never thought to google for something like this before. There probably aren’t too many good uses for it, but it saved me a bunch of time today so I thought I’d share:
Running a query like the one below, would return all the values from my sub-select as a comma delimited list so this…
SELECT products.namename,
        GROUP_CONCAT(options.option) AS options
FROM products
     INNER JOIN options
     ON          options.productID = products.productID
Could return something like this:
NAMEOPTIONS
t-shirtgreen, blue, red, small, medium, large
hatcowboy

0 comments:

Post a Comment