470,602 Members | 1,652 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

How to Get 4th Largest salary without using "join" or "where" in SQL ?

Hello,

Is there any by which I can write a SQL to get the 4th largest salary from a table without using "join" and without using "where" clause.

Suppose the table is having two columns : Employee_id, Employee_salary.

Please let me know..

I faced this question in an interview and I did not have any answer for this.

Regards,
San
Apr 27 '07 #1
2 3329
Hi,
you will have to use either join or where for getting forth highest salary.

use nested query

select max(salary) from emp where salary<(select max(salary) from emp where salary<(select max(salary) from emp where salary<(select max(salary) from emp)))

use corrlated query

select * from emp e where 3=(select count(distinct sal) from emp x where x.sal>e.sal)
Apr 27 '07 #2
Hello,

Is there any by which I can write a SQL to get the 4th largest salary from a table without using "join" and without using "where" clause.

Suppose the table is having two columns : Employee_id, Employee_salary.

Please let me know..

I faced this question in an interview and I did not have any answer for this.

Regards,
San
Assuming that you have 4 or more rows in the table:

Select Top 4 * from Emp order by Employee_salary desc

The 4th row is the one that you want.
Apr 30 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Rachel Weeden | last post: by
3 posts views Thread by Martin | last post: by
9 posts views Thread by Frederik | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.