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

Retrieve first 100 records


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

New User


Joined: 16 Jul 2009
Posts: 3
Location: pune

PostPosted: Tue Jul 21, 2009 1:43 pm
Reply with quote

Hi ,

How i can retrieve first 100 records from a db2 to table.

regards,
Niki
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Jul 21, 2009 1:46 pm
Reply with quote

COBOL, SPUFI, REXX

Please explain your question fully, and show us what problems you have encountered with your code.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Tue Jul 21, 2009 2:10 pm
Reply with quote

You can use
Code:
FETCH FIRST 100 ROWS ONLY
with the SQL
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Jul 21, 2009 2:33 pm
Reply with quote

Quote:
How i can retrieve first 100 records from a db2 to table


you can not retreive records from a db2 table- you can only retrieve rows.

first 100 records Ordered or Unordered?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Tue Jul 21, 2009 5:33 pm
Reply with quote

bipinpeter wrote:
You can use
Code:
FETCH FIRST 100 ROWS ONLY
with the SQL
Without ORDER BY it'll give you some garbage...
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Wed Jul 22, 2009 10:45 am
Reply with quote

Hi Anuj,
Quote:
Without ORDER BY it'll give you some garbage...
.
What u mean by 'some garbage?[/quote]
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Wed Jul 22, 2009 11:24 am
Reply with quote

Quote:
What u mean by 'some garbage?


DB2 does not store the rows in any predefined order. So without order by clause, it may fetch any 100 rows which does not make any sense.
The only fetch first statement thats meaningful without order by is
Code:
FETCH FIRST ROW ONLY
existence check.
Back to top
View user's profile Send private message
bipinpeter

Active User


Joined: 18 Jun 2007
Posts: 213
Location: Cochin/Kerala/India

PostPosted: Wed Jul 22, 2009 11:30 am
Reply with quote

Okay Bharath and Anuj..I got the point
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Jul 22, 2009 5:43 pm
Reply with quote

DB2 is a relational Database -- there is nothing like first, last or middle from DB2 per se. The ORDER BY clause is required to sort the results in the correct order. If it is removed from the query, the results will still contain the top ten, but they may be in no particular order.

As you will learn if you continue to work with databases, there is no such thing as "first n rows". You might retrieve some n rows, but there is nothing automatically "first" about them.

If you read the same sequential file 10 times, the first n records will always be the first n. If you read a table n times, the first n rows may or may not be the same ones each time...
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


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

PostPosted: Wed Jul 22, 2009 7:00 pm
Reply with quote

Here is an intrestinng article on The “Top Ten” Problem.
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 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 Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Using Java/C/C++ to retrieve dataset ... Java & MQSeries 6
Search our Forums:

Back to Top