Home » RDBMS Server » Server Administration » How to select the latest two rows
How to select the latest two rows [message #370389] Fri, 17 September 1999 12:03 Go to next message
Rajeeva
Messages: 20
Registered: October 1998
Junior Member
I want to select the latest two records for a member.

The table is

Key is
member_id varchar2(5)
member_date date

There can be multiple records for a member_id with a different date. How can I select the latest two rows. (just two rows for a member_id)

Thanks
Re: How to select the latest two rows [message #370391 is a reply to message #370389] Fri, 17 September 1999 15:32 Go to previous messageGo to next message
m a sivan
Messages: 34
Registered: July 1999
Member
select * from emp where member_date >=
(select member_date from emp a where 1 =
(select count(distinct (member_date)) from emp b where b.member_date > a.member_date)
and rownum and member_date IS NOT NULL)

Let me know if this solves ur problem. I assume the member date is generated using sysdate ....

this will give the last 2 rows inserted and if u wanna do for particular member u can add that in the Query like (where member_id = XXX ) after the final line...

Thanks
Sivan
Re: How to select the latest two rows [message #370394 is a reply to message #370389] Fri, 17 September 1999 16:39 Go to previous messageGo to next message
Prashanth
Messages: 41
Registered: September 1999
Member
Also you can Try this:-

SELECT max(A.COL1) first,max(B.COL1) second
FROM
TEST A,
TEST B
WHERE B.COL1
***col1 is a date field
Re: How to select the latest two rows [message #370460 is a reply to message #370391] Tue, 28 September 1999 18:05 Go to previous message
Rajeeva
Messages: 20
Registered: October 1998
Junior Member
Thanks Sivan, It worked, Rajeeva
Previous Topic: Returning to sql script
Next Topic: Bug 902521: FUNCTION BASED INDEX
Goto Forum:
  


Current Time: Fri Oct 30 03:07:57 CDT 2020