If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > comma separated resultset

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-11-06, 10:46
cstevio cstevio is offline
Registered User
 
Join Date: Feb 2004
Posts: 17
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 12:59. Reason: Solution Found
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On