表格用户
usrid names country city
------------------------
1 john doe uk landon
2 jane deo uk landon
表味精
msg_id msg_from msg_to
----------------------
1 ID 1 ID 2
现在-示例
msg_id msg_from msg_to
----------------------
1 ID 1 from tbl USERS - get names for this ID from table users ID 2 from tbl USERS - get names for this ID from table users
我如何通过从表msg中进行选择来获取名称以及如何使用单个mysql语句从表用户中获取名称 就像加入
答案 0 :(得分:0)
所以JOIN的工作方式如下:
SELECT msg_id, msgfrom.name AS msg_from, msgto.name AS msg_to
FROM MSG
JOIN USERS msgfrom ON msg_from = msgfrom.usrid
JOIN USERS msgto ON msg_to = msgto.usrid