write a query to find 4th max salary
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.
What are triggers and its uses?
Why is normalization important?
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.
How to handle bulk data?
What is relationship? How many types of relationship are there?
how to enter binary numbers in sql statements? : Sql dba
What's the difference between inner join and left join?
hi,i plan to put experience on PLSQL ,can anyone suggest me for any institutes in bangalore or how to prepare for interviews
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
What are aggregate functions in sql?
How do I edit a stored procedure?