how to retrieve the top 3 salaries of the table using rownum
Answers were Sorted based on User's Feedback
Answer / chandrasekar.ramasamy
select sal from( select rownum,e.* from empmaster e order
by sal desc) where rownum < 4
Is This Answer Correct ? | 20 Yes | 7 No |
Answer / dhiman sarkar
select empname,sal from (select empname,sal from dh1 order
by sal desc)
where rownum < =4
order by sal desc
Is This Answer Correct ? | 17 Yes | 7 No |
Answer / kalyan kumar
select e.ename,e.sal from emp e where 3>(select count
(distinct(b.sal)) from emp b where b.sal>e.sal)
Is This Answer Correct ? | 19 Yes | 10 No |
Answer / vik
select empno, ename, sal from (select * from emp order by
sal desc) where rownum < 4
Is This Answer Correct ? | 8 Yes | 1 No |
Answer / nilesh
You can also use a query like
select e.ename,e.sal from emp e where 3>(select count
(distinct(b.sal)) from emp b where b.sal>e.sal)
as explained by Kalyan Kumar in Answer 2 and for making
it parameterised u can replace 3 by &sal so that when it is
executed it will ask you a number
if you enter 3 it will give you best three salaries , if
you enter 4 it will give you best 4 salaries etc.
Is This Answer Correct ? | 9 Yes | 3 No |
Answer / rameshwar gupta
select ename ,sal from (select ename,sal from emp order
by sal desc)
where rownum<4
Is This Answer Correct ? | 8 Yes | 3 No |
Answer / moorthy(information dynamic)
select sal,rank()over (order by sal desc) from emp where
rownum < = 3;
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / nitesh
select sal from emp e where 3>=(select count(distinct sal)
from emp where sal>e.sal) order by sal desc;
Is This Answer Correct ? | 5 Yes | 3 No |
Answer / akki julak
select sal from (select rownum,sal from emp order by sal
desc)
where rownum<4;
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / swapnareddy
select sal from emp a where 3>(select
count(distinct(sal))from emp b where a.sal<b.sal);
Is This Answer Correct ? | 4 Yes | 3 No |
How do you retrieve the last N records from a table?
what is sql server agent? : Sql dba
wht is the difference between truncat,drop in sqlserver wht is the difference between function and stored procedure
Explain the update statement in sql
what are the forced views
What is Function based Index and which type of function we can use in Function base index. can we use aggregate,NVL function in Function based Index..
1 Answers Metric Stream, Polaris,
Difference between truncate, delete and drop commands?
What are hotfixes and patches?
What is extent clause in table space?
How many sql core licenses do I need?
How do you retrieve set of records from database server. {Set max records = 100 & use paging where pager page no or records = 10 & after displaying 100 records again connect to database retrieve next 100 }
What is duration in sql profiler trace?