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
 

 

Query to retrieve first 7 rows.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Prasad Toshniwal
Warnings : 1

New User


Joined: 05 May 2008
Posts: 4
Location: PUNE

PostPosted: Thu Sep 04, 2008 1:01 pm    Post subject: CURSOR query
Reply with quote

Prasad Toshniwal wrote:
If there are 20 rows in one table and i need to retrieve first 7 rows only.How to do this.IS it compulsory to use cursor here and if yes please let me know the query.
Thanks,
Prasad.
Back to top
View user's profile Send private message

Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Thu Sep 04, 2008 1:33 pm    Post subject:
Reply with quote

Hi Prasad,

Is your last post in continuation with the first post of this thread ? However, check these link if they serve the purpose -

http://ibmmainframes.com/viewtopic.php?t=27071&highlight=row
http://ibmmainframes.com/viewtopic.php?t=25806&postdays=0&postorder=asc&start=15
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: Thu Sep 04, 2008 7:35 pm    Post subject:
Reply with quote

Hello Prasad,

First - when you have a new question, you should start a new topic for your question rather than reply to some existing topic.

Second - as you will learn if you contnue to work with databases, there is no such thing as "first 7 rows". You might retrieve some 7 rows, but there is nothing automatically "first" about them. If you read the same sequential file 5 times, the first 7 records will always be the first 7. If you read a table 7 times, the first 7 rows may or may not be the same ones each time.
Back to top
View user's profile Send private message
shabir46

New User


Joined: 24 Jan 2008
Posts: 6
Location: Kerala

PostPosted: Fri Sep 05, 2008 4:10 pm    Post subject:
Reply with quote

Hi Prasad,

If you want to just retrieve the first 7 rows from a table, you can use the 'FETCH FIRST 7 ROWS ' command to serve the purpose.

Or if you want to do achive the same purpose through a program, then you can use the cursor and use the cursors iteratively to get 7 rows.


Shabir
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Fri Sep 05, 2008 7:10 pm    Post subject:
Reply with quote

Hello,
shabir46 wrote:
If you want to just retrieve the first 7 rows from a table, you can use the 'FETCH FIRST 7 ROWS ' command to serve the purpose.
Without an "ORDER By" clause this query would be just garbage..

Check the links posted before in this thread, you would get the reason behind with details..
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 Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


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