IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Retrieve first 3 records of my table without using cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chandracdac

New User


Joined: 15 Jun 2007
Posts: 92
Location: bangalore

PostPosted: Wed Aug 29, 2007 5:37 pm
Reply with quote

i want to retrieve first 3 records of my table without using cursor . can anybody help me?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Aug 29, 2007 7:23 pm
Reply with quote

Hello,

There is no such thing as "the first 3 records" in an active database table.

How would you define the first 3?
Back to top
View user's profile Send private message
jaspal

New User


Joined: 22 May 2007
Posts: 68
Location: mumbai

PostPosted: Thu Aug 30, 2007 10:52 am
Reply with quote

in cobol we can't retrieve more than one record without cursor

regards,
Jaspal
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu Aug 30, 2007 11:36 am
Reply with quote

then use 3 selects.

select fields from yourtable
FETCH FIRST 1 ROW ONLY

select fields from yourtable
where key>lastkey
FETCH FIRST 1 ROW ONLY

select fields from yourtable
where key>lastkey
FETCH FIRST 1 ROW ONLY
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Aug 30, 2007 4:40 pm
Reply with quote

acevedo, what if the clustering index is different than the primary key?
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu Aug 30, 2007 5:56 pm
Reply with quote

dick scherrer wrote:
Hello,

There is no such thing as "the first 3 records" in an active database table.

How would you define the first 3?


if you join Dick answer to your answer then my conclusion is:
only the OP knows what he's trying to get...

and if my previous post you add ORDER BY WHATEVERYOURKEYFIELDHERE....then.. it should work.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Aug 30, 2007 6:00 pm
Reply with quote

No one ever defines what they want other than the "first x rows" or "second y rows". These types of statements are no good in a database. The concept is just wrong in a database world. If they would say the "first x rows ordered by my primary key where the key is > xxx" then we could give them a sensible answer. But no one ever does.
Back to top
View user's profile Send private message
acevedo

Active User


Joined: 11 May 2005
Posts: 344
Location: Spain

PostPosted: Thu Aug 30, 2007 6:05 pm
Reply with quote

stodolas wrote:
No one ever defines what they want other than the "first x rows" or "second y rows". These types of statements are no good in a database. The concept is just wrong in a database world. If they would say the "first x rows ordered by my primary key where the key is > xxx" then we could give them a sensible answer. But no one ever does.


simply... right!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To fetch records that has Ttamp value... DFSORT/ICETOOL 4
No new posts ICETOOL returns no records JCL & VSAM 1
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Load new table with Old unload - DB2 DB2 6
Search our Forums:

Back to Top