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
 

 

Fetch first 10 records from a table having 1000 records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Fetch first 10 records from a table having 1000 records
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: 413
Location: Colarado, US

PostPosted: Thu Dec 15, 2005 10:08 am    Post subject: Re: Fetch first 10 records
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    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Nov 08, 2007 12:34 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Thu Nov 08, 2007 2:36 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Nov 08, 2007 2:47 am    Post subject: Reply to: Fetch first 10 records from a table having 1000 re
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    Post subject:
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

Site Director


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

PostPosted: Sat Nov 10, 2007 2:39 am    Post subject:
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

Active Member


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

PostPosted: Mon Nov 12, 2007 8:23 pm    Post subject:
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    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 Loading data to table gives wrong for... Raghu navaikulam DB2 16 Thu Jul 13, 2017 2:11 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am
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 1 Sat Apr 22, 2017 1:32 pm
No new posts after TBSARG: Row 370 from 1000 Pedro TSO/ISPF 1 Fri Apr 14, 2017 2:32 am


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