Adeel A. Malik
Adeel A. Malik

Reputation: 23

ERROR: missing FROM-clause entry for table

SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND apr.sha=Regions.sha
GROUP BY "region"

Following error given:

ERROR: missing FROM-clause entry for table "regions"

Upvotes: 2

Views: 9685

Answers (2)

Skywalker
Skywalker

Reputation: 1774

try this:

SELECT "region", sum("items"), sum("actcost")
FROM "apr","Regions"
WHERE "bnfname" LIKE 'Flucloxacillin %' AND "apr"."sha"="Regions"."sha"
GROUP BY "region"

Upvotes: 1

Shubham Batra
Shubham Batra

Reputation: 2375

SELECT apr.region, 
       SUM(apr.items), 
       SUM(apr.actcost) 
FROM   apr, 
       Regions 
WHERE  apr.bnfname LIKE 'Flucloxacillin %' 
       AND apr.sha = regions.sha 
GROUP  BY apr.region

Or use join

SELECT apr.region, 
       SUM(apr.items), 
       SUM(apr.actcost) 
FROM   apr 
       join regions 
         ON apr.sha = regions.sha 
WHERE  apr.bnfname LIKE 'Flucloxacillin %' 
GROUP  BY apr.region 

Upvotes: 0

Related Questions