加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 16:27:26 所属栏目:百科 来源:网络整理
导读:我有以下SQL(PostgreSQL)查询: SELECT ff.*,fp.*FROM fibra ff,fibra fpJOIN cables cp ON fp.cable_id = cp.idLEFT OUTER JOIN terceiro ced_pai ON ced_pai.id = cp.cedente_idLEFT OUTER JOIN terceiro tp ON tp.id = fp.terceiro_idJOIN cables cf ON f
我有以下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?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读