write a query to find 4th max salary

Answers were Sorted based on User's Feedback



write a query to find 4th max salary..

Answer / raj

for example if we take emp table:

select a.sal from emp a where 4=(select count(distinct(b.sal)) from emp b where a.sal<=b.sal);

Is This Answer Correct ?    3 Yes 1 No

write a query to find 4th max salary..

Answer / debashis mohanty

Select Name,Deptno,Salary,Rank from
(
Select Ename Name,Deptno,Sal Salary,Rank () over(Order By Sal Desc) Rank from emp
)
Where Rank=4

Is This Answer Correct ?    2 Yes 0 No

write a query to find 4th max salary..

Answer / nishi.swain@gmail.com

select distinct sal from table_name t1 where 4=(select count(distinct sal) from table_name t2 where
t1.sal<=t2.sal);

Is This Answer Correct ?    0 Yes 0 No

write a query to find 4th max salary..

Answer / raj

for example if we take emp table, the query like this...
select a.sal from emp a where 4=(select count(distinct(b.sal))from emp b where a.sal<=b.sal)

Is This Answer Correct ?    0 Yes 0 No

write a query to find 4th max salary..

Answer / sreeharibabu

SELECT id
FROM (select salary2.*, rownum rnum from
(select * from test ORDER BY id DESC) salary2
where rownum <=4)
WHERE rnum >= 4;

Is This Answer Correct ?    0 Yes 0 No

write a query to find 4th max salary..

Answer / mujahid

Simple one is i think:
Select min(sal) from (select sal from emp order by sal desc LIMIT 4);

Is This Answer Correct ?    0 Yes 0 No

write a query to find 4th max salary..

Answer / anand v

select user_name,sal,rank over(order by sal desc) rank from table
where rank =4

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More SQL PLSQL Interview Questions

how to retrieve last tree records from table? select *from emp where rownum > (select count(*)-3 from emp); i am using this query to get last three records from table but its not giving any output, so please tell me what is the error in this query.

16 Answers  


What are triggers and its uses?

0 Answers  


Why is normalization important?

0 Answers  


SELECT emp_num, years, SUM(salary) FROM sales UNION ALL SELECT emp_id, SUM(takehomepay) FROM marketing What error is present in the sample code above? 1. Queries being combined with the UNION ALL statement are not allowed to have SELECT lists with a different number of expressions. 2. You are not allowed to use aggregate functions within two queries joined by a UNION ALL statement. 3. The UNION ALL statement incorrectly combines the "years" result from the first query with the "SUM (takehomepay)" result from the second query. 4. Unless the UNION ALL statement is replaced with a UNION statement, the queries will return duplicates. 5. The "emp_id" column from the second query must be renamed (or aliased) as "emp_num" so that it corresponds to the column name from the first query. Otherwise, the queries will not execute.

3 Answers  


How to handle bulk data?

0 Answers  






What is relationship? How many types of relationship are there?

0 Answers  


how to enter binary numbers in sql statements? : Sql dba

0 Answers  


What's the difference between inner join and left join?

0 Answers  


hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews

0 Answers  


2. Select A.A from ( select 1 as from dual Union select 1 as from dual)A Full outer join ( select 1 B from dual Union select 2 B from dual)B On A.A=B.B

2 Answers   Fintellix,


What are aggregate functions in sql?

0 Answers  


How do I edit a stored procedure?

0 Answers  


Categories