[英]relate 2 columns of another table
I have the following 2 tables in Mysql:我在 Mysql 中有以下 2 个表:
table name:store (store user id's)
emp dst
1 2
1 3
2 1
3 1
4 2
table name:users
id name
1 empA
2 empB
3 empC
4 empD
How should my query be to obtain the following result based on the store table?我的查询应该如何根据商店表获得以下结果?
result
emp dst
empA empB
empA empC
empB empA
empC empA
empD empB
Just join store
and users
together.只需将
store
和users
连接在一起。 But you should join users
twice as you want names for both emp and dst.但是您应该两次加入
users
,因为您需要 emp 和 dst 的名称。
So the query might be:所以查询可能是:
SELECT u1.name AS emp, u2.name AS dst
FROM store AS s
JOIN users AS u1 ON s.emp = u1.id
JOIN users AS u2 ON s.dst = u2.id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.