I am trying to select items from table1 which has a child table2 there is a third table3 involved.
Select j.ccmasterid,
(Select sum(i.ccmatpullqty) From table2 i
Where i.ccmasterid = j.ccmasterid) pulled
from table1 j
INNER JOIN table3 s on j.ccstatus = s.sysstatusid and s.ccopenjob=false
where j.ccmasterid LIKE 'W%' and pulled = 0
This generates an error:
ERROR: column "pulled" does not exist LINE 6: where j.ccmasterid LIKE 'W%' and pulled = 0
If I take the "and pulled = 0" out the the query, it works as one would expect producing a list of records from table1 with the sum of the values in table2 as pulled.
ccmasterid pulled
W106063 0
W100553 9
W100685 1
WHAT I can't figure out is how to select based on pulled being 0.