ERROR: invalid reference to FROM-clause

后端 未结 2 647
孤街浪徒
孤街浪徒 2021-01-01 10:36

I have the following SQL (PostgreSQL) query:

SELECT ff.*, fp.*
FROM fibra ff, fibra fp

JOIN cables cp ON fp.cable_id = cp.id
LEFT OUTER JOIN terceiro  ced_p         


        
2条回答
  •  难免孤独
    2021-01-01 11:25

    You are mixing implicit and explicit JOINs. That's generally confusing to read, and leads to unexpected order-of-evaluation problems, as you've just discovered.

    You should consistently use JOIN ... ON syntax everywhere; avoid the legacy FROM table1, table2. If you correct your query to use an explicit JOIN instead of FROM fibra ff, fibra fp, eg FROM fibra ff INNER JOIN fibra fp ON (ff.fibra_pai_id = fp.id) and omit ff.fibra_pai_id = fp.id from the WHERE clause, you should get the expected result.

    See this question that A.H. linked to:

    Mixing explicit and implicit joins fails with "There is an entry for table ... but it cannot be referenced from this part of the query"

提交回复
热议问题