postgresql – ERROR:对FROM子句的引用无效

前端之家收集整理的这篇文章主要介绍了postgresql – ERROR:对FROM子句的引用无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下sql(Postgresql)查询
SELECT ff.*,fp.*
FROM fibra ff,fibra fp

JOIN cables cp ON fp.cable_id = cp.id
LEFT OUTER JOIN terceiro  ced_pai ON ced_pai.id = cp.cedente_id
LEFT OUTER JOIN terceiro tp ON tp.id = fp.terceiro_id

JOIN cables cf ON ff.cable_id = cf.id
LEFT OUTER JOIN terceiro ced_f ON ced_f.id = cf.cedente_id
LEFT OUTER JOIN terceiro tf ON tf.id = ff.terceiro_id

where ff.fibra_pai_id = fp.id 
AND ff.cable_id IN (8,9,10) 
AND fp.cable_id IN (8,10)

但它给我这个错误

ERROR:  invalid reference to FROM-clause entry for table "ff"
LINE 8:  JOIN cables cf ON ff.cable_id = cf.id
           ^
HINT:  There is an entry for table "ff",but it cannot be referenced from this part of the query.

********** Error **********

ERROR: invalid reference to FROM-clause entry for table "ff"
sql state: 42P01
Hint: There is an entry for table "ff",but it cannot be referenced from this part of the query.
Character: 261

有谁知道我做错了什么?

你正在混合隐式和显式的JOIN.这通常是令人困惑的阅读,并导致意外的评估阶段问题,正如你刚刚发现的.

你应该始终使用JOIN … ON语法无处不在;避免遗留FROM table1,table2.如果您更正您的查询以使用明确的JOIN而不是FROM纤维ff,则可以从WHERE子句中忽略ff.fibra_pai_id = fp.id,例如,从原始文件ff INNER JOIN fibra fp ON(ff.fibra_pai_id = fp.id)你应该得到预期的结果.

看到这个问题,A.H.链接到:

What’s wrong with this query?

猜你在找的Postgre SQL相关文章