tags:

views:

45

answers:

2

I have two tables, Profiles and ProfileInformation.

Any profile may have multiple entries in ProfileInformation.

I am trying to create a query that takes all of the profile information for a specific profile and put it in to a single field, for example:

Profile[0] has 3 corresponding records in ProfileInformation, lets say phone numbers. I would like to return a result set like:

ID, AllProfileInformation

or

0, 1234567890 1234567890 1234567890

1, 1234567890 1234567890 1234567890

Something along the lines of SELECT Profiles.ID, (SELECT pi.Values FROM ProfileInformation pi WHERE pi.ID = Profiles.ID) as AllProfileInformation FROM Profiles

+3  A: 

You'll need to use the mysql specific group_concat function.

select p.id, group_concat(pi.Values separator ' ') as AllProfileInformation
from profiles p
  inner join profileinformation pi on (pi.ID = p.ID)
group by pi.id
Senseful
exactly what i was looking for, i knew there had to be a better way. thank you.
Steve
and if anyone cares, I had to add GROUP BY p.id to select many
Steve
+1  A: 

CONCAT is what you're looking for.

RaYell