SQL 缺少表的 FROM 子句条目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23557563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:51:26  来源:igfitidea点击:

missing FROM-clause entry for table

sqlpostgresql

提问by Olavakodan

I am trying to use an inner joina view and a table using the following query

我正在尝试使用inner join以下查询来使用视图和表

SELECT 
   AcId, AcName, PldepPer, RepId, CustCatg, HardCode, BlockCust, CrPeriod, CrLimit, 
   BillLimit, Mode, PNotes, gtab82.memno 
FROM
   VCustomer 
INNER JOIN   
   vcustomer AS v1 ON gtab82.memacid = v1.acid 
WHERE (AcGrCode = '204' OR CreDebt = 'True') 
AND Masked = 'false'
ORDER BY AcName

and the error is

错误是

missing FROM-clause entry for table "gtab82"

采纳答案by Patrick

SELECT 
   AcId, AcName, PldepPer, RepId, CustCatg, HardCode, BlockCust, CrPeriod, CrLimit, 
   BillLimit, Mode, PNotes, gtab82.memno 
FROM
   VCustomer AS v1
INNER JOIN   
   gtab82 ON gtab82.memacid = v1.AcId 
WHERE (AcGrCode = '204' OR CreDebt = 'True') 
AND Masked = 'false'
ORDER BY AcName

You typically only use an alias for a table name when you need to prefix a column with the table name due to duplicate column names in the joined tables and the table name is long or when the table is joined to itself. In your case you use an alias for VCustomerbut only use it in the ONclause for uncertain reasons. You may want to review that aspect of your code.

由于连接的表中的列名重复并且表名很长或当表与自身连接时,您通常只在需要使用表名作为列前缀时才使用表名的别名。在您的情况下,您使用别名 forVCustomerON出于不确定的原因仅在子句中使用它。您可能希望查看代码的该方面。

回答by znurgl

Because that gtab82 table isn't in your FROM or JOIN clause. You refer gtab82 table in these cases: gtab82.memno and gtab82.memacid

因为那个 gtab82 表不在您的 FROM 或 JOIN 子句中。在这些情况下,您可以参考 gtab82 表:gtab82.memno 和 gtab82.memacid