View previous topic :: View next topic
|
Author |
Message |
abhicet2003
New User
Joined: 16 Nov 2005 Posts: 21
|
|
|
|
Could any one tell me how to fech first 10 records from a table having 1000 records |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
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 |
|
|
abhicet2003
New User
Joined: 16 Nov 2005 Posts: 21
|
|
|
|
Thanks this query has worked fine. |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
That query will provide inconsistent results without and ORDER BY clause in your select. The requirement is poorly defined. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Why are you two responding to a two year old posting that the OP was happy with? |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Wow, it just showed up on my new changes list. I didn't even look at the date stamp |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Bill,
What i saw was from today - i didn't look back at the dates
This has been asked several times recently and i just thought it was someone else with the same homework
d |
|
Back to top |
|
|
HARLEEN SINGH MANN Warnings : 2 New User
Joined: 03 Aug 2007 Posts: 17 Location: Pune
|
|
|
|
Can someone please explain why is thr no last or first row in a table? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
|