dbTalk Databases Forums  

single concatenated result from a table select.

comp.databases.mysql comp.databases.mysql


Discuss single concatenated result from a table select. in the comp.databases.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
The Natural Philosopher
 
Posts: n/a

Default single concatenated result from a table select. - 12-03-2010 , 09:06 AM






What is the correct way to do this?

I want to select a subset email addresses from a table and present them
as a comma delimited single result.

ie.e the result will be :

'fred (AT) bloogs (DOT) com,sue (AT) mouse (DOT) com,charley (AT) watts (DOT) com'
Is this concat() and a 'group by' thing?

Reply With Quote
  #2  
Old   
Luuk
 
Posts: n/a

Default Re: single concatenated result from a table select. - 12-03-2010 , 09:22 AM






On 03-12-10 16:06, The Natural Philosopher wrote:
Quote:
What is the correct way to do this?

I want to select a subset email addresses from a table and present them
as a comma delimited single result.

ie.e the result will be :

'fred (AT) bloogs (DOT) com,sue (AT) mouse (DOT) com,charley (AT) watts (DOT) com'
Is this concat() and a 'group by' thing?
GROUP_CONCAT() is the function to use

see:
http://dev.mysql.com/doc/refman/5.0/...n_group-concat

--
Luuk

Reply With Quote
  #3  
Old   
The Natural Philosopher
 
Posts: n/a

Default Re: single concatenated result from a table select. - 12-03-2010 , 09:33 AM



The Natural Philosopher wrote:
Quote:
What is the correct way to do this?

I want to select a subset email addresses from a table and present them
as a comma delimited single result.

ie.e the result will be :

'fred (AT) bloogs (DOT) com,sue (AT) mouse (DOT) com,charley (AT) watts (DOT) com'
Is this concat() and a 'group by' thing?
A bit of googling led me to this:

This worked, but seems ugly..

select
1 as g,
group_concat(email separator ',') as them
from people
where status>1
group by g;


is there no other way than creating a constant dummy field to group all
results in a select?

It works well enough. Just seems a bit clumsy..

Reply With Quote
  #4  
Old   
Luuk
 
Posts: n/a

Default Re: single concatenated result from a table select. - 12-03-2010 , 09:42 AM



On 03-12-10 16:33, The Natural Philosopher wrote:
Quote:
The Natural Philosopher wrote:

What is the correct way to do this?

I want to select a subset email addresses from a table and present
them as a comma delimited single result.

ie.e the result will be :

'fred (AT) bloogs (DOT) com,sue (AT) mouse (DOT) com,charley (AT) watts (DOT) com'
Is this concat() and a 'group by' thing?

A bit of googling led me to this:

This worked, but seems ugly..

select
1 as g,
group_concat(email separator ',') as them
from people
where status>1
group by g;


is there no other way than creating a constant dummy field to group all
results in a select?

It works well enough. Just seems a bit clumsy..
just do:
select
group_concat(email separator ',') as them
from people
where status>1





--
Luuk

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.