mySQL Super-tip! How to comma-delimit or comma-separate your query results!

| No Comments »

_Problem_: Help! I’d like to make it so my query results to be a comma delimited format!

_Answer_: No problemo! Simply use mySQL’s group_concat function and you’ll get your results in comma delimited values!

SELECT GROUP_CONCAT(id) FROM users WHERE authenticated=1 ORDER BY NULL LIMIT 1 Note: (Optional) ORDER BY NULL is used to prevent unnecessary sorting with filesort

This query would result to: 1,3,4,6,11

That’s It! This is pretty useful when you are going to use the SELECT… IN statement for your subqueries.

Leave a Reply