开发者

Simple mysql query (i think) - select multiple rows into 1 field

I have two tables, Profiles and ProfileInformation.

Any profile may have multiple en开发者_如何学Gotries 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


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


CONCAT is what you're looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜