Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Retrieve first 3 records of my table without using cursor

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Retrieve first 3 records of my table without using cursor
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

Site Director


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

PostPosted: Wed Aug 29, 2007 7:23 pm    Post subject:
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    Post subject: Re: Retrieve first 3 records of my table without using curso
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Update table without cursor Ron Klop DB2 3 Wed Oct 11, 2017 1:06 pm
No new posts Table(Unicode(Graphic) table) loading... muralikrishnan_new DB2 0 Thu Oct 05, 2017 5:10 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us