Question:
How can I get 5th highest sal. from employee tab?
Answer:
Select max(sal) from emp where sal<(select max(sal) from emp where sal<(select max (sal) from emp where sal<(select max (sal) from emp where sal<(select max(sal) from emp)))); Source: CoolInterview.com
Answered by: shushant arora | Date: 7/15/2008
| Contact shushant arora
SELECT TOP 1 salary FROM (SELECT DISTINCT TOP 5 salary FROM employee ORDER BY salary DESC) a ORDER BY salary Source: CoolInterview.com
Answered by: Ashok | Date: 8/13/2008
| Contact Ashok
FOR nth HIGHEST ENTRY:- SELECT MAX(SALARY) FROM employee e1 WHERE &N = ( SELECT COUNT(DISTINCT(SALARY)) FROM employee e2 WHERE e1.SALARY <= e2.SALARY);
Put the value for the n & you can find any no. of highest salary. Source: CoolInterview.com
Answered by: Amit Goyal | Date: 8/26/2008
| Contact Amit Goyal
select rownum,employee_id,salary from (select employee_id,salary from employees order by salary desc) where rownum<=5; Source: CoolInterview.com
Answered by: vishakha agrawal | Date: 9/15/2008
| Contact vishakha agrawal
SELECT COLUMNNAME FROM TABLENAME T1 WHERE N=(SELECT COUNT(DISTINCT(COLUMNNAME)) FROM TABLENAME T2 WHERE T1.COLUMNNAME>=T2.COLUMNNAME) ORDER BY COLUMNNAME;
WHERE N=IS THE POSITION Source: CoolInterview.com
Answered by: Dhananjay GM | Date: 10/13/2008
| Contact Dhananjay GM
SELECT * FROM( SELECT a.*,ROWNUM r FROM scott.emp a ORDER BY sal DESC) WHERE r=5 Source: CoolInterview.com
Answered by: Bhushan Salgar | Date: 11/26/2008
| Contact Bhushan Salgar
SELECT min (salary) FROM ( SELECT salary FROM employees ORDER BY salary DESC) WHERE ROWNUM < 6 ORDER BY salary Source: CoolInterview.com
Answered by: ibrahim hamza | Date: 4/1/2010
| Contact ibrahim hamza
Select level,max(sal) from employee where level=5 connect by prior sal>sal group by level Source: CoolInterview.com
Answered by: ASHISH GAUTAM | Date: 5/30/2010
| Contact ASHISH GAUTAM
SELECT employee_id , salary FROM (SELECT employee_id , salary , dense_rank() over (order by salary desc) poradi -- 5th value --, row_number() over (order by salary desc) poradi -- 5th row FROM employees) WHERE poradi = 5; Source: CoolInterview.com
Answered by: Lenka | Date: 6/24/2010
| Contact Lenka
SELECT * FROM `employee` ORDER BY `sallery` DESC LIMIT 4 , 1 Source: CoolInterview.com
Answered by: sunil | Date: 8/27/2010
| Contact sunil
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|