我的表格如下:
reg table
id | user_id
--------------
7 | 8
10 | 11
位置表
id | reg_id | location_number
-----------------------------
4 | 7 | 111111
5 | 10 | 222222
6 | 10 | 333333
机器表
id | location_id | type
-----------------------
1 | 4 | local
2 | 5 | local
3 | 6 | international
我想要的结果是检索与其他相关数据相同的reg_id,如下所示:
reg_id | location_number | user_id | location_id
-------------------------------------------------
10 | 222222 | 11 | 5
10 | 333333 | 11 | 6
我的查询是:
select * from reg
join location on reg.id = location.reg_id
join machines on location.id = machines.location_id
where reg.id = 10
但是这个查询只返回一行。
需要协助才能达到上述效果。感谢
答案 0 :(得分:0)
也许你可以试试:
select location.reg_id, location. location_number, reg.user_id, machines.location_id
from reg
join location on reg.id = location.reg_id
join machines on location.id = machines.location_id
where reg.id = 10