我想制定特定的 JOIN 顺序
SELECT *
FROM (lives_in as t1 NATURAL JOIN preferences p1) l1
JOIN (lives_in t2 NATURAL JOIN preferences p2) l2
ON l1.dormid = l2.dormid
返回错误。
任何人都可以帮忙吗?非常感谢!
您的别名查询缺少一个SELECT
子句,所以试试这个:
SELECT *
FROM (
select * -- added this
FROM lives_in as t1
NATURAL JOIN preferences p1) l1
JOIN (
select * -- added this
FROM lives_in t2
NATURAL JOIN preferences p2) l2
ON l1.dormid = l2.dormid
连接的顺序与结果无关。你可能想要这样的东西:
SELECT *
FROM lives_in t1
NATURAL JOIN preferences p1 ON p1.some_id = t1.id
NATURAL JOIN preferences p2 ON p2.some_id = t1.id
此外,大多数人称其为 INNER JOIN,而不是 NATURAL JOIN,顺便说一句。
希望它会有所帮助。
SELECT *
FROM (
select * from lives_in as t1 NATURAL JOIN preferences p1
) l1
JOIN (
select * from lives_in t2 NATURAL JOIN preferences p2
) l2
ON l1.dormid = l2.dormid