find the third highest salary?
Answers were Sorted based on User's Feedback
Answer / selvaraj v, anna university co
Find the HIGHEST SALARY in Employee Table :
-------------------------------------------
select * from emp where sal=(select max(sal) from emp)
order by empno;
Find the 3'rd HIGHEST SALARY in Emp Table :
-----------------------------------------------
SELECT * FROM EMP e WHERE 3=(SELECT COUNT(*) FROM EMP x
WHERE x.SAL>=E.SAL);
It's e,x are ALIAS NAME of EMP Table.
| Is This Answer Correct ? | 14 Yes | 2 No |
Answer / noorulahaq
select min(sal) from emp where sal in (
select sal from
( select sal from emp order by sal desc )
where rownum <=3 )
| Is This Answer Correct ? | 26 Yes | 17 No |
Answer / rohit kumar
select min(sal) from (select sal from emp order by sal
desc) where rownum <= 3
| Is This Answer Correct ? | 17 Yes | 8 No |
Answer / uday kiran
Its is like Nth highest salary.....
Select * from Employee where salary =
(Select max(Salary) from Employee where salary < (Select max
(Salary) from Employee where
Salary<(Select max(Salary) from Employee where
Salary <…………………………………………… N
| Is This Answer Correct ? | 15 Yes | 10 No |
Answer / nripesh agarwal
select * from emp where salary=(select distinct salary from
emp order by salary desc limit n,1)
// for Nth highest value put n=N-1....
//for 3rd highest put n=2........
| Is This Answer Correct ? | 7 Yes | 2 No |
Answer / srinath reddy
select * from emp e1 where 3 = (select count(*) from emp e2
where e1.salary <= e2.salary);
instead of answer we can say this as a solution where we can
find nth also
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / imran ansari
find n th highest salary replace n with 1,2,3....to find second,third,fourth........sal
SELECT sal from emp order by sal desc limit 2,1
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / nripesh agarwal
select * from emp where salary=(select salary from emp
order by salary desc N,1);
// Put the value for N as for Nth highest salary
// e.g. for 2nd put N=2 , for 3rd put N=3 and so on...
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / chandra sekhar
SELECT * FROM EMP e
where 3=(select count(*) from emp
where e.sal<=sal)
Using this correlated subquery we can easily get any one
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / kiran
select salary from employees e where 3 = (select count
(distinct salary) from employees f where
e.salary <= f.salary);
| Is This Answer Correct ? | 1 Yes | 0 No |
How do we tune the code?
What is difference between joins and union?
How to create a view on a table which does not exists
what is overloading procedure or overloading function ?
what are dynamic queries in t-sql? : Transact sql
Why is there a need for sqlcode and sqlerrm variables?
What is Raise_application_error ?
Write a query to find the employees from EMP table those who have joined in Monday. (there is a column as hiredate which is a date column i.e values are like 03-DEC-81)
Explain UNION,MINUS,UNION ALL, INTERSECT?
What are sql data types?
What sql does db2 use?
What is embedded sql in db2?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)