Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2004
    Posts
    17

    Unanswered: comma separated resultset [Solution Found!]

    Hi,

    I've a table where there are bits of data I want to group together as such:

    ----------------
    |id |name | val |
    ----------------
    |1 |test | 2 |
    ----------------
    |2 |test | 10 |
    ----------------
    |3 |test | 8 |
    ----------------

    I want to group by the name column and have the val colum be return as a comma separated list as follows:

    ---------------
    |name| val |
    ---------------
    |test | 2,10,8|
    ---------------

    is there a function that could do that in MYSQL without writing an SP...

    Any help would be much appreciated.

    Steve

    NB:
    Thanks to someone on another forum I've found a solution.

    For anybody else who may have the same problem look up GROUP_CONCAT()

    In the above instance I used the follow query:

    SELECT name, GROUP_CONCAT(val)
    FROM table
    GROUP BY name
    Last edited by cstevio; 01-11-06 at 13:59. Reason: Solution Found

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •