user209306
user209306

Reputation: 89

Something syntactically wrong with this SQL statement?

I keep getting an error when I try running this query in mysqlite3:

SELECT Region_DESC, AgeGroup, Population
(select REGION, sum(POPULATION) as Population, '0-15' AS AgeGroup
from STATS
Where Age between 0 and 15
group by REGION
union
Select REGION, SUM(POPULATION) as Population, '16-30' As AgeGroup
from STATUS
Where Age between 16 and 30
group by REGION) s
join REGION on REGION_CD = REGION

I'm getting the following error: Error: near "SELECT": syntax error

Is there anything wrong with the query, syntax-wise?

Upvotes: 0

Views: 224

Answers (3)

Naval
Naval

Reputation: 344

Incorrect Query ... missing From Clause in the first line.

Upvotes: 0

sashkello
sashkello

Reputation: 17871

Your query is wrong. You basically have:

SELECT something
(select somethingelse FROM somethingelsetable) s
join REGION on REGION_CD = REGION

I guess you are missing FROM before the parentheses...

Upvotes: 2

bob
bob

Reputation: 452

You're missing FROM right after the word 'Population'.

Upvotes: 2

Related Questions