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

Fetch first 10 records from a table having 1000 records


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

New User


Joined: 16 Nov 2005
Posts: 21

PostPosted: Thu Dec 15, 2005 9:56 am
Reply with quote

Could any one tell me how to fech first 10 records from a table having 1000 records
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Thu Dec 15, 2005 10:08 am
Reply with quote

Hi abhjicet2003,

Check the answer for your query

Quote:
to fech first 10 records from a table having 1000 records


Answer

Code:
SELECT * FROM tablename FETCH FIRST 10 ROWS ONLY



Hope this helps.
Back to top
View user's profile Send private message
abhicet2003

New User


Joined: 16 Nov 2005
Posts: 21

PostPosted: Thu Dec 15, 2005 11:07 am
Reply with quote

Thanks this query has worked fine.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Wed Nov 07, 2007 11:28 pm
Reply with quote

That query will provide inconsistent results without and ORDER BY clause in your select. The requirement is poorly defined.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Nov 08, 2007 12:34 am
Reply with quote

Hello,

To repeat something that has been posted many times.

There is no such thing as the first n rows in a table.

The posted query will retrieve 10 rows, but there is nothing "first" about them.

The results of that query are unpredictable.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Nov 08, 2007 2:36 am
Reply with quote

Why are you two responding to a two year old posting that the OP was happy with? icon_rolleyes.gif
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Nov 08, 2007 2:42 am
Reply with quote

Wow, it just showed up on my new changes list. I didn't even look at the date stamp
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Nov 08, 2007 2:47 am
Reply with quote

Hi Bill,

What i saw was from today - i didn't look back at the dates icon_redface.gif

This has been asked several times recently and i just thought it was someone else with the same homework icon_smile.gif

d
Back to top
View user's profile Send private message
HARLEEN SINGH MANN
Warnings : 2

New User


Joined: 03 Aug 2007
Posts: 17
Location: Pune

PostPosted: Sat Nov 10, 2007 12:11 am
Reply with quote

Can someone please explain why is thr no last or first row in a table?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Sat Nov 10, 2007 2:39 am
Reply with quote

Hello,

Tables do not have a "start" and an "end", or a "first/last" or a "front/back". These are concepts for sequential processing.

Tables have rows that are in no particular order. If you need a result set in some order, the way to guarantee the sequence of the result set that meets the selection criteria is to specify the order in the query. If the result set is a single row, ordering is not an issue - a single row is just that.

When someone talks about the first or last rows in a table it makes no sense without specifying the order by which the first/last rows are defined.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon Nov 12, 2007 8:23 pm
Reply with quote

To slightly clarify for beginners, there may in fact be some physical order to the rows, since they are in fact stored in some kind of file structure (which the system (e.g., DB2), but not the user, must be concerned about), but no query can/should/will guarantee you consistent retrieval if you have not specified ORDER BY.

Similarly, of you do specify ORDER BY, but have sets of rows with identical values in the all of the order columns, rows within each of these sets will be presented in an arbitrary order, and maybe not even the same order each time. So - for repeated testing, you might achieve different results with the same set of data.
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 Load new table with Old unload - DB2 DB2 6
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top