Connecting Tech Pros Worldwide Help | Site Map

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

Member
 
Join Date: Jan 2007
Posts: 45
#1: Apr 27 '07
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
Newbie
 
Join Date: Feb 2007
Posts: 15
#2: Apr 27 '07

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


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)
Newbie
 
Join Date: Apr 2007
Posts: 1
#3: Apr 30 '07

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


Quote:

Originally Posted by santoshsri

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.
Reply