Thursday, March 12, 2009

MySQL implode like function

If you need an implode like function in MySQL, there is a solution: GROUP_CONCAT

GROUP_CONCAT concatenates a string by comma (,).

So if you had a table tags (id, tag)

1 test
2 test2
3 test3

SELECT GROUP_CONCAT(tag) FROM tags

The result would be: test,test2,test3

Pretty cool, huh?

No comments: