View previous topic :: View next topic |
Author |
Message |
jagan Beginner
Joined: 27 Jan 2003 Posts: 5 Topics: 4
|
Posted: Mon Feb 17, 2003 3:56 am Post subject: first 5 records from a db2 table |
|
|
how to retrive first 5 records from a db2 table
pl let me know the answer |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
jagan Beginner
Joined: 27 Jan 2003 Posts: 5 Topics: 4
|
Posted: Tue Feb 18, 2003 2:08 am Post subject: |
|
|
thanks kolusu
is it possible to get last 5 records from a table?in the same way? |
|
Back to top |
|
|
Himesh CICS Forum Moderator
Joined: 20 Dec 2002 Posts: 80 Topics: 21 Location: Chicago
|
Posted: Tue Feb 18, 2003 3:15 am Post subject: |
|
|
Jagan,
If you had referred to the same link that Kolusu had posted, you would have come across the following statement:
Quote: |
If both the FETCH FIRST clause and the ORDER BY clause are specified, the ordering is performed on the entire result set prior to returning the first n rows.
|
So, you could fetch the last 5 rows by using an ORDER BY DESC clause in your SQL.
Example:
Code: |
SELECT *
FROM TABLE
WHERE Col1 = :host-var
ORDER BY COL1 DESC
FETCH FIRST 5 ROWS ONLY
;
|
regards,
Himesh |
|
Back to top |
|
|
|
|