繁体   English   中英

检索具有相似列mysql的表

[英]Retrieve tables with similar columns mysql

我的表如下所示:

注册表

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

但是此查询仅返回一行。

需要协助才能达到上述效果。 谢谢

也许您可以尝试:

    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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM