1

也许你可以帮助我:

我有一张桌子:

1: Users
id   username   email
1    myname     myname@myname.com
2    myname2    myname2@myname.com

2: Accounts
user_id   account
1         37992054
2         3804933 
1         23286966

我需要提出请求并获取以下数据:

id   username   email                account
1    myname     myname@myname.com    37992054, 23286966
2    myname2    myname2@myname.com   3804933
4

2 回答 2

4

您需要连接两个表并使用分组结构来折叠具有相同用户 ID 的记录:

Select u.id, u.username, u.email, group_concat(a.account)
from users as u join accounts as a 
  on a.user_id = u.id
group by u.id;
于 2012-05-17T12:13:58.897 回答
0

您需要一个标准的连接查询:

select u.id,u.username,u.email,a.account from Users as u, Accounts as a where u.id=a.id;
于 2012-05-17T12:15:16.187 回答