Go Back  IT Forums > Software > Oracle
User Name
Password
Reply
 
Thread Tools Search this Thread Display Modes

Fetching last three records from a table
  #1
Old 10-02-2006, 08:16 AM
Hassan Ayub
Junior Member


Hassan Ayub is offline
Hassan Ayub's Info
Join Date: Sep 2004
Posts: 3
Default Fetching last three records from a table

Hi Folks,

I have the following master-detail tables:

CASES

D_NO VARCHAR2(20)
D_DATE DATE
BUDGET_HEAD VARCHAR2(50)
CONC_PO VARCHAR2(50)
AMOUNT NUMBER
REMARKS VARCHAR2(400)
DIV VARCHAR2(30)

DESCRIPTION VARCHAR2(2000)
SUB_HEAD VARCHAR2(50)


F_DEM_PROG

D_NO VARCHAR2(20)
REC_FROM VARCHAR2(500)
SENT_TO VARCHAR2(500)
TD_DATE DATE
ACTION VARCHAR2(500)
REMARKS VARCHAR2(2000)
SNO NUMBER




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

Reply With Quote
Fetching last three records from a table
  #2
Old 10-02-2006, 09:34 AM
Sybrand Bakker
Junior Member


Sybrand Bakker is offline
Sybrand Bakker's Info
Join Date: Feb 2004
Posts: 117
Default Fetching last three records from a table

On 2 Oct 2006 09:16:45 -0700, hassan_ayub@yahoo.com wrote:
Quote:
Hi Folks, I have the following master-detail tables: CASESD_NO VARCHAR2(20)D_DATE DATEBUDGET_HEAD VARCHAR2(50)CONC_PO VARCHAR2(50)AMOUNT NUMBERREMARKS VARCHAR2(400)DIV VARCHAR2(30)DESCRIPTION VARCHAR2(2000)SUB_HEAD VARCHAR2(50) F_DEM_PROGD_NO VARCHAR2(20)REC_FROM VARCHAR2(500)SENT_TO VARCHAR2(500)TD_DATE DATEACTION VARCHAR2(500)REMARKS VARCHAR2(2000)SNO NUMBER I need to have the last three records from each d_no . What wouldbe the query which will return last three records from each d_nodepending whatever div is selected by the user. Hassan


This group doesn't do your work for free.

--
Sybrand Bakker, Senior Oracle DBA
Reply With Quote
Fetching last three records from a table
  #3
Old 10-02-2006, 11:17 AM
DA Morgan
Junior Member


DA Morgan is offline
DA Morgan's Info
Join Date: May 2005
Posts: 474
Default Fetching last three records from a table

hassan_ayub@yahoo.com wrote:
Quote:
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
Reply With Quote
Fetching last three records from a table
  #4
Old 10-02-2006, 08:36 PM
Hassan Ayub
Junior Member


Hassan Ayub is offline
Hassan Ayub's Info
Join Date: Sep 2004
Posts: 3
Default Fetching last three records from a table

DA Morgan wrote:
Quote:
hassan_ayub@yahoo.com wrote:
Quote:
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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump



Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Style Design by vBStyles.com


Top Contact Us - IT Forums - Archive - MyLounge Top
MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service