Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - using a value in a nested select

Tags:

sql

oracle

nested

Hope the title makes some kind of sense - I'd basically like to do a nested select, based on a value in the original select, like so:

SELECT MAX(iteration) AS maxiteration,
       (SELECT column
        FROM   table
        WHERE  id = 223652
               AND iteration = maxiteration)
FROM   table
WHERE  id = 223652;  

I get an ORA-00904 invalid identifier error.

Would really appreciate any advice on how to return this value, thanks!

like image 497
Nick Avatar asked May 26 '11 13:05

Nick


1 Answers

It looks like this should be rewritten with a where clause:

select iteration,
       col
from tbl
where id = 223652
and iteration = (select max(iteration) from tbl where id = 223652);
like image 171
Denis de Bernardy Avatar answered Oct 12 '22 13:10

Denis de Bernardy