How to concatenate results in a mysql query (similar to using the PHP implode function to concatenate an array)

Say that I have a table in my database like the one below:

SELECT * FROM cms_releases;
Name Latest stable release Latest release date
Drupal 7.7 2011-07-27
Joomla 1.7.0 2011-07-19
Mambo 4.6.5 2008-06-01
WordPress 3.2.1 2011-07-12[
Xaraya 1.2.1 2010-05-16
Zikula 1.2.7 2011-05-02

I want to query the above table and I want to get a coma separated sting that contains all the entries in the name column. I could write a PHP script that would iterate over the results of a simple SELECT query but I could also use the mysql GROUP_CONCAT function:

SELECT GROUP_CONCAT(name) as names FROM cms_releases ;

And get the desired result:

Drupal, Joomla, Mambo, WordPress, Xaraya, Zikula

Comments

hi

hi

Wham bam thank you, ma'am, my

Wham bam thank you, ma'am, my questions are awnsered!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

10 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.