MySQL语句查询

一张A表关联到另一张B表,A表的一个A.groupId 与 B表的 B.groupId是关联关系,但没有主外键关系,查询 A表, 根据A.groupId查询B表的IP字段,但B表有多条相同B.groupId的记录 。现在的目的是,查询A表 把B表有相同的B.groupId 的 IP 全部查询出来,并用逗号‘,’连接起来做一个字段展示在查询语句中。

具体看下面示意:

A 表
Aid groupId name
1 1 x
2 2 y

B表
Bid groupId IP
1 1 1.1.1.1
2 1 2.2.2.2
3 2 3.3.3.3

查询语句 select **********************

结果
Aid A.groupId IP name
1 1 1.1.1.1,2.2.2.2 x
2 2 3.3.3.3 y

这样的查询语句怎么写呢?只能用SQL语句实现,数据库是MySql!

[code="sql"]
select a.aId,a.groupId,group_concat(b.ip),a.name
from A a left join B b on a.groupId=b.groupId group by a.groupId;

#group_concat 默认以","隔开.

/**
如报错,请及时反馈。
**/
[/code]

select A.Aid, group_concat(B.IP, separator ',') ,name FROM
A ,B where A.groupId=B.groupId;

select A.Aid, group_concat(B.IP, separator ',') ,A.name FROM
A ,B where A.groupId=B.groupId; group by A.Aid

这个问题和我之前回复过的
[url]http://www.iteye.com/problems/88164#s_187053[/url]类似