我想在两张桌子中使用内心。
我的表格为users
,relations
和users
(再次)。我想relations
与users
sender_id
加入reveiver_id
并再次加入select * from
(relations inner join users on relations.sender_id = users.userid)
inner join users on relations.reciever_id = users.userid
。
我的示例代码是:
{{1}}
但此代码未运行。为什么呢?
答案 0 :(得分:3)
如果要使用子查询,则可以使用此查询 -
SELECT * FROM
(SELECT * FROM `relations`
INNER JOIN `users`
ON `relations`.`sender_id` = `users`.`userid`) t
INNER JOIN `users`
ON t.`reciever_id` = `users`.`userid`
但它与 -
相同SELECT * FROM `relations`
INNER JOIN `users`
ON `relations`.`sender_id` = `users`.`userid`
INNER JOIN `users`
ON `relations`.`reciever_id` = `users`.`userid`
答案 1 :(得分:1)
SELECT *
FROM `relations` AS r INNER JOIN
`users` AS u1 on r.`sender_id` = u1.`userid` INNER JOIN
`users` AS u2 on r.`reciever_id` = u2.`userid`