Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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 Testing rerad cursor for status with ... John F Dutcher DB2 8 Fri May 19, 2017 9:35 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts unload data from table with lob columns farhad_evan DB2 0 Sat Apr 22, 2017 1:32 pm
No new posts Data replication from multiple Db2 ta... kishpra DB2 9 Mon Mar 27, 2017 9:58 pm
No new posts Getting -504 Cursor Name GTT-ARTS-CUR... Robin Sulsona DB2 2 Fri Mar 17, 2017 1:43 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us