Home » SQL & PL/SQL » SQL & PL/SQL » nth Max row in a table-giving problem
nth Max row in a table-giving problem [message #2031] Tue, 18 June 2002 04:21 Go to next message
hanu
Messages: 21
Registered: March 2002
Junior Member
The following query gives me the nth max row.

select a.sal from emp a
where &n = (select count(*) from emp b
where b.sal >= a.sal);

My problem is that, in case of duplicate rows it's giving the problem. Suppose the 4th and 5th rows are equal in that case, I am not getting the 4th max row and getting 5th Max row as two rows.

Can we say that it's correct. In fact, I should get 4th max row itself as 2rows.

How can get it?

Thanks in advance for your help

Hanu
Re: nth Max row in a table-giving problem [message #2034 is a reply to message #2031] Tue, 18 June 2002 06:57 Go to previous message
koteswara rao p.
Messages: 10
Registered: June 2002
Junior Member
hi hanu
here is the solution for your problem

select distinct(a.sal) from emp a where
&n=(select count (distinct(b.sal)) from emp b
where a.sal<=b.sal)
have a nice day
regards
koti
Previous Topic: Re: Error in reading CLOB
Next Topic: Problem with update
Goto Forum:
  


Current Time: Fri Apr 26 06:58:54 CDT 2024