Postgresql-在多个表上执行左联接时遇到问题

Postgresql-在多个表上执行左联接时遇到问题,sql,postgresql,syntax-error,Sql,Postgresql,Syntax Error,我正在将一些Mysql查询转移到Postgresql,我遇到了一个不起作用的查询 select (tons of stuff) from trip_publication left join trip_collection AS "tc" on tc.id = tp.collection_id left join trip_author ta1, (dies here) trip_person tp1, trip_i

我正在将一些Mysql查询转移到Postgresql,我遇到了一个不起作用的查询

select (tons of stuff)
from trip_publication 

left join trip_collection AS "tc" on
tc.id = tp.collection_id

left join 
            trip_author ta1, (dies here)
            trip_person tp1,
            trip_institution tai1,
            trip_location tail1,
            trip_rank tr1
    ON
            tp.id = ta1.publication_id 
            AND tp1.id = ta1.person_id 
            AND ta1.order = 1 
            AND tai1.id = ta1.institution_id 
            AND tail1.id = tai1.location_id 
            AND ta1.rank_id = tr1.id
这个查询似乎在“trip_author ta1”行中消失了,我在上面做了标记。实际的错误消息是:

   syntax error at or near ","
   LINE 77:   (trip_author ta1, trip_person tp1, ... 

我看了一下文件,似乎是对的。我到底做错了什么?任何反馈都将不胜感激。

我不知道postgres,但在常规SQL中,您需要一系列
左连接
语句,而不是逗号语法。你似乎已经开始这样做了,但在前两次之后就停止了

比如:

SELECT * FROM
table1 
LEFT JOIN table2 ON match1
LEFT JOIN table3 ON match2
WHERE otherFilters
另一种选择是较旧的SQL语法:

SELECT cols
FROM table1, table2, table3
WHERE match AND match2 AND otherFilters
SQL中还有几个较小的错误,比如您在第一个表中忘记了
tp
别名,并尝试将
where
子句(
ta1.order=1
)作为连接约束

我想这就是你想要的:

select (tons of stuff)
from trip_publication tp 
left join trip_collection AS "tc" on tc.id = tp.collection_id
left join trip_author ta1 on ta1.publication_id  = tp.id
left join trip_person tp1 on tp1.id = ta1.person_id 
left join trip_institution tai1 on  tai1.id = ta1.institution_id 
left join trip_location tail1 on tail1.id = tai1.location_id 
left join trip_rank tr1 on tr1.id = ta1.rank_id
where ta1.order = 1

左联接是每个要联接的表的一个联接

left join trip_author ta1 on ....
left join trip_person tp1 on ....
left join trip_institution on ...
……等等