a query to select maxmun 3 salaries of employee table
Answers were Sorted based on User's Feedback
Answer / tulasi
select * from (select * from emp order by sal desc) where
rownum<=3;
| Is This Answer Correct ? | 21 Yes | 5 No |
Answer / krishna kumar r
SELECT E1.ENAME,E1.SAL FROM EMP E1 WHERE 3>(SELECT COUNT(*)
FROM EMP E2 WHERE E2.SAL>E1.SAL ) ORDER BY SAL DESC
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / chaitanya
Select sal from emp order by desc fetch first 3 rows only;
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / munna
select * from emp e where &n=(select count(distinct sal)
from emp ee where e.sal<=ee.sal);
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / suresh babu
select * from employees a where 3 <= select count(distinct
b.salary) from employees b where a.salary >= b.salary);
This query,which returns the first maximum salary from
employees table.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dhanya
select rnk, no,sal from (
SELECT DENSE_rank()over(partition by no order by sal desc ) RNK,d2.no,sal FROM DUMMY2 d2)
where rnk =2;
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / kannan
select * from emp
where sal in (select max(sal) from emp
where level<=3
connect by prior sal>sal
group by level)
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / raju
select * from emp a where 3>=(select count(distinct(b.sal))
from emp b where b.sal>=a.sal )
| Is This Answer Correct ? | 4 Yes | 6 No |
select top 3 salary from employee order by salary desc
| Is This Answer Correct ? | 5 Yes | 7 No |
Answer / ron
if you need to select by department then analytic function
is more readable:
1. use row_number() partition by dept order by sal desc as rn,
2. in where clause choose rn <4;
you can use rank() instead; if 2 or more employees have same
salary.
| Is This Answer Correct ? | 0 Yes | 3 No |
Calculate difference between 2 date / times in oracle sql?
13. Display the second to fifth characters in each client name.
How will you differentiate between varchar & varchar2?
How to upsert (update or insert into a table)?
5. Display full details for the creditor/s who has received the single largest payment. Do not use a table join or set operator anywhere in your query.
What are the factors causing the reparsing of SQL statements in SGA?
What is the difference between RBBMS & DBMS?
What is a nvl function? How can it be used?
Is a rollback possible to any savepoint?
what is a Nested Loop join?
In what script is snap$ created? In what script is the scott/tiger schema created?
difference between imlicit cursor and explicit cursor ?