Hi,
Can anybody please explain me the flow of the below query.
I am not able to understand how this query works.
This query is for finding the Nth highest salary..
SELECT DISTINCT (a.sal)
FROM EMP A
WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B
WHERE a.sal<=b.sal);
If N = 2 then second highest salary will be the o/p.
If N = 3 then third highest salary will be the o/p.
and so on..
Thanks,
Nitin
Answer Posted / avi
Above Answer is correct With small modification that it is a
corelated sub query first it considers sal from a like a.sal
then it compares with all the sal in a sub query the result
will be the no. of counts.This count compares with N value
which matches will be the Nth sal.
Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
How do you modify a trigger?
Explain the structure of pl/sql in brief.
How do I remove all records from a table?
what is an index? : Sql dba
How can I get the number of records affected by a stored procedure?
What are few of the schema objects that are created using PL/SQL?
how to get a list of all tables in a database? : Sql dba
what is a primary key? : Sql dba
Does view store data in sql?
Is subquery faster than join?
What is bind variable in pl sql?
how to rename an existing table in mysql? : Sql dba
what are the 'mysql' command line arguments? : Sql dba
How many sectors are in a partition?
how to get @@error and @@rowcount at the same time? : Sql dba