Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing FROM-clause entry for table [closed]

Tags:

sql

postgresql

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

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"
like image 883
Olavakodan Avatar asked May 09 '14 05:05

Olavakodan


2 Answers

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 VCustomer but only use it in the ON clause for uncertain reasons. You may want to review that aspect of your code.

like image 111
Patrick Avatar answered Oct 22 '22 06:10

Patrick


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

like image 28
znurgl Avatar answered Oct 22 '22 06:10

znurgl