Re: Fetching last three records from a table

From: <hassan_ayub_at_yahoo.com>
Date: 2 Oct 2006 21:36:02 -0700
Message-ID: <1159850162.778291.90070_at_m7g2000cwm.googlegroups.com>


DA Morgan wrote:
> hassan_ayub_at_yahoo.com wrote:
>
> > I need to have the last three records from each d_no . What would
> > be the query which will return last three records from each d_no
> > depending whatever div is selected by the user.
> >
> > Hassan
>
> Define "last three." Heap tables don't have an order.
>
> Show us your current best attempt and we will give you a hint.
> --
> Daniel Morgan
> University of Washington
> Puget Sound Oracle Users Group

Hi,

 Each record in the ind_prog table is saved with a sequence number in the SNO field, therefore the last three records for each d_no will be its last three maximun sequence number. I used the following query which works fine for a single d_no on the f_dem_prog table:

                select d_no,rec_from,sent_to,td_date,sno
from(select d_no,rec_from,sent_to,td_date,sno from f_dem_prog where d_no='&d_no'
order by sno desc) where rownum<4

thanks Received on Tue Oct 03 2006 - 06:36:02 CEST

Original text of this message