View previous topic :: View next topic
|
Author |
Message |
deepak_nag Warnings : 1 New User
Joined: 16 Jun 2006 Posts: 4
|
|
|
|
I have a DB2 table ,I donot know the structure of the table,but i know there are 100 rows.Now i have to fetch only 98th and 99th row only.How can we realise this by query ? |
|
Back to top |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
|
|
Deepak,
It's a difficult case may i know your exact requirement. where you are suppose to utilize your above scenario? |
|
Back to top |
|
|
anamikak
New User
Joined: 10 May 2006 Posts: 64 Location: Singapore
|
|
|
|
1. Find out the primary key of your table from SYSIBM.SYSCOLUMS.
2. then try out the fetch first n records as:
Select * from 'tablename'
order by primary key DESC.
fetch first 3 rows only. |
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Code: |
SELECT * FROM
(SELECT * FROM <CREATOR>.<TABLE> FETCH FIRST N ROWS ONLY)
FETCH LAST ROW ONLY; |
Replace N with the row-number you like to retrieve. |
|
Back to top |
|
|
anoopkhetan
New User
Joined: 22 Sep 2006 Posts: 3 Location: mumbai
|
|
|
|
Hi,
See Query
Select * from 'tablename'
order by primary key DESC where Primary key < max(primary key)
fetch first 2 rows only
Anoop |
|
Back to top |
|
|
|