0

我想制定特定的 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

返回错误。

任何人都可以帮忙吗?非常感谢!

4

3 回答 3

2

您的别名查询缺少一个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
于 2013-10-15T05:53:38.983 回答
1

连接的顺序与结果无关。你可能想要这样的东西:

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,顺便说一句。

于 2013-10-15T05:48:05.500 回答
1

希望它会有所帮助。

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
于 2013-10-15T06:27:10.907 回答