相关疑难解决方法(0)

错误:对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,9,10)
Run Code Online (Sandbox Code Playgroud)

但它给了我这个错误:

ERROR:  invalid reference to FROM-clause entry for table …
Run Code Online (Sandbox Code Playgroud)

postgresql join

22
推荐指数
1
解决办法
3万
查看次数

内连接和外连接; 表格的顺序是重要的吗?

为什么在组合外部和内部连接时表的顺序很重要?postgres失败如下:

SELECT grp.number AS number,     
       tags.value AS tag   
FROM groups grp,
     insrel archiverel  
LEFT OUTER JOIN ownrel ownrel ON grp.number = ownrel.dnumber   
LEFT OUTER JOIN tags tags ON tags.number = ownrel.snumber   
WHERE archiverel.snumber = 11128188 AND    
      archiverel.dnumber = grp.number 
Run Code Online (Sandbox Code Playgroud)

结果:

ERROR:  invalid reference to FROM-clause entry for table "grp" LINE 5: LEFT OUTER JOIN ownrel ownrel ON grp.number = ownrel.d... 
^ HINT:  There is an entry for table "grp", but it cannot be referenced from this part of the query. …
Run Code Online (Sandbox Code Playgroud)

postgresql

16
推荐指数
3
解决办法
3万
查看次数

查询(子查询)的此部分无法引用该条目

我在查询中遇到以下错误:

here is an entry for table "table1", but it cannot be referenced from this part of the query.
Run Code Online (Sandbox Code Playgroud)

这是我的查询:

SELECT id 
FROM property_import_image_results table1
  LEFT JOIN (
    SELECT created_at 
    FROM property_import_image_results
    WHERE external_url = table1.external_url
    ORDER BY created_at DESC NULLS LAST 
    LIMIT 1
  ) as table2 ON (pimr.created_at = table2.created_at)
WHERE table2.created_at is NULL
Run Code Online (Sandbox Code Playgroud)

sql postgresql

3
推荐指数
1
解决办法
4985
查看次数

标签 统计

postgresql ×3

join ×1

sql ×1