View previous topic :: View next topic
|
Author |
Message |
nikipathak
New User
Joined: 16 Jul 2009 Posts: 3 Location: pune
|
|
|
|
Hi ,
How i can retrieve first 100 records from a db2 to table.
regards,
Niki |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
COBOL, SPUFI, REXX
Please explain your question fully, and show us what problems you have encountered with your code. |
|
Back to top |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
You can use
Code: |
FETCH FIRST 100 ROWS ONLY |
with the SQL |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Hi Anuj,
Quote: |
Without ORDER BY it'll give you some garbage... |
.
What u mean by 'some garbage?[/quote] |
|
Back to top |
|
|
Bharath Bhat
Active User
Joined: 20 Mar 2008 Posts: 283 Location: chennai
|
|
|
|
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 |
|
|
bipinpeter
Active User
Joined: 18 Jun 2007 Posts: 213 Location: Cochin/Kerala/India
|
|
|
|
Okay Bharath and Anuj..I got the point |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
Back to top |
|
|
|