by http://webgeektutorials.blogspot.com

Monday, May 14, 2012

Oracle DBA Script : Find out two top values from a table

1. Finds the two highest salaries from table "emp".

Code:
select a.empno,a.sal
from emp a
where 2>
(
select count(*)
from emp
where sal>a.sal
);


2. Finds the two lowest salaries from table "emp".


Code:
select a.empno,a.sal
from emp a
where 2>
(
select count(*)
from emp
where sal<a.sal
)

3 comments:

Anonymous said...

for mysql what to do?


plz mail me at gajendrapratap2012@gmail.com

Thanks....

Shardul Singh said...

In Mysql you can use order by and limit. For eg.

select * from table_name order by some_field [asc|desc] limit 5

will select 5 records as per ASC / DESC order.
Hope it helps.. :)

Anonymous said...

thanks ..

Post a Comment