简单的mysql查询(我认为) - 在1个字段中选择多行

时间:2010-06-04 13:54:36

标签: sql mysql

我有两个表,个人资料个人资料信息

任何个人资料在ProfileInformation中都可能有多个条目。

我正在尝试创建一个查询,该查询获取特定配置文件的所有配置文件信息并将其放入单个字段中,例如:

Profile [0]在ProfileInformation中有3条相应的记录,比方说电话号码。我想返回一个结果集,如:

ID,AllProfileInformation

0,1234567890 1234567890 1234567890

1,1234567890 1234567890 1234567890

有些东西 SELECT Profiles.ID,(选择pi.Values FROM ProfileInformation pi WHERE pi.ID = Profiles.ID)作为AllProfileInformation FROM个人资料

2 个答案:

答案 0 :(得分:3)

您需要使用特定于mysql的group_concat函数。

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

答案 1 :(得分:1)

CONCAT正是您要找的。

相关问题