Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Please explain this query
shihab wrote:
> This is the query to findout Nth Max (Highest) value from a table
>
> SELECT sal from emp t
> WHERE &n = (SELECT COUNT(sal)
> FROM (SELECT DISTINCT sal FROM emp)
> WHERE t.sal<=sal);
>
> Can anybody expalin how this query works.....
>
>
> Thanks in advance
> Shihab
That is a bit of a puzzler, isn't it?
Try re-arranging the SQL a bit, and it may become more clear.
SELECT sal,
(
SELECT COUNT(sal)
FROM (SELECT DISTINCT sal FROM emp)
WHERE t.sal<=sal
) rank
from emp t
order by sal
Received on Thu Oct 13 2005 - 17:50:20 CDT
![]() |
![]() |