JOEZACK.COM Code Musings and Such

28Jan/090

Today’s Favorite 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:

GROUP_CONCAT

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:

name options
t-shirt green, blue, red, small, medium, large
hat cowboy
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Tagged as: Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.