Matt Phillips
Matt Phillips

Reputation: 11519

sqlite subquery syntax error

I have a syntax error in this subquery that I cannot seem to figure out why it won't work. All the parens are matched

select min(max_s) 
from 
(select max(salary) from instructor group by dept_name) 
as s(max_s);

Error: near "(": syntax error

Upvotes: 2

Views: 4462

Answers (3)

OMG Ponies
OMG Ponies

Reputation: 332571

Use:

SELECT MIN(x.max_s) 
  FROM (SELECT MAX(i.salary) AS max_s 
          FROM INSTRUCTOR i
      GROUP BY i.dept_name) x

Upvotes: 3

Bill Karwin
Bill Karwin

Reputation: 562330

Don't put parens after a table alias.

Upvotes: 0

martin clayton
martin clayton

Reputation: 78115

The problem is in the AS s(max_s) table alias, which doesn't look quite right. You should alias the column name inside the subquery, for example:

select min(s.max_s) 
from 
(select max(salary) as max_s from instructor group by dept_name) 
as s

Upvotes: 2

Related Questions