Home » SQL & PL/SQL » SQL & PL/SQL » A question about top n values
A question about top n values [message #202722] Sat, 11 November 2006 05:29 Go to next message
prince973
Messages: 37
Registered: November 2006
Member
hi all
if we want to get the min two salaries from scott.emp table we do the following:

select sal,rownum from
(select sal from emp order by sal)
where ROWNUM<3;
and we get :

SAL ROWNUM
---------- ----------
800 1
950 2
my question is , what if i want to get the second min salary only , i tried this :

select sal,rownum from
(select sal from emp order by sal)
where ROWNUM=2;
no rows selected

as u can see , i got no result .
what is ur opinion??
Re: A question about top n values [message #202723 is a reply to message #202722] Sat, 11 November 2006 05:35 Go to previous messageGo to next message
vamsi kasina
Messages: 2112
Registered: October 2003
Location: Cincinnati, OH
Senior Member
Have you searched the forum..... at least FAQ..?

FAQ

Hope you can change that query, as you required.

By
Vamsi.
Re: A question about top n values [message #202783 is a reply to message #202723] Sun, 12 November 2006 11:03 Go to previous messageGo to next message
ab_trivedi
Messages: 460
Registered: August 2006
Location: Pune, India
Senior Member
hi prince,

have you tried the problem again?

Ashu
Re: A question about top n values [message #202812 is a reply to message #202722] Sun, 12 November 2006 23:10 Go to previous message
romi
Messages: 67
Registered: October 2006
Member

U can try it to find second min value:-

select max(sal) from (select sal from emp order by sal) where rownum<=2
Previous Topic: SQLLDR SCRIPT
Next Topic: date formet
Goto Forum:
  


Current Time: Sat Dec 07 00:19:51 CST 2024