View previous topic :: View next topic
|
Author |
Message |
Abirami.YN
New User
Joined: 16 Jul 2005 Posts: 15 Location: India - Chennai
|
|
|
|
HI,
I have to display last 10 records and
3rd to 5 th record from the same table.
How can i do ? |
|
Back to top |
|
|
parikshit123
Active User
Joined: 01 Jul 2005 Posts: 269 Location: India
|
|
|
|
Hi Abirami.YN,
In RDBMS, there is nothing like Nth record.
so, retriving 10 last records from a DB2 table doesn't make any sence. |
|
Back to top |
|
|
Abirami.YN
New User
Joined: 16 Jul 2005 Posts: 15 Location: India - Chennai
|
|
|
|
HI Parikshit chudasma
We can retrive using the following code.
But i am getting -104 error.
I think this because of DB2 Version ( Iam not sure)
select * from (
select rownumber() over(order by fieldname) as r
from tablename
) as temptablename where r<= 10 |
|
Back to top |
|
|
Prasanthhere
Active User
Joined: 03 Aug 2005 Posts: 306
|
|
|
|
Try this
Select * from table name fetch last 10 rows |
|
Back to top |
|
|
radhakrishnan82
Active User
Joined: 31 Mar 2005 Posts: 435 Location: chennai, India
|
|
|
|
Fetch last 10 rows will do. |
|
Back to top |
|
|
ovreddy
Active User
Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
|
|
|
|
Hi,
SELECT * FROM <<TABLE NAME>> ORDER BY <<Primary Key>> DESC FETCH FIRST 10 ROWS ONLY;;
It will work. Don't say that u don't have a Primary Key. If So how can you say that these are last 10 records. If you do not agree on this give me a real time situation where we need this.
If you say that it is asked in some X Interview then ask them for a real situation. If they are really good enough about CODD'S rules they will agree with you.
Thanks,
Reddy. |
|
Back to top |
|
|
thiagold
New User
Joined: 29 Nov 2005 Posts: 3
|
|
|
|
ovreddy wrote: |
SELECT * FROM <<TABLE NAME>> ORDER BY <<Primary Key>> DESC FETCH FIRST 10 ROWS ONLY;;
|
That way do not work ins DB2 V6, only V7 or +. Anybody knows how to do it in DB2 V6?? |
|
Back to top |
|
|
dgrinch
New User
Joined: 16 Nov 2005 Posts: 4
|
|
|
|
Not sure if it's for batch or online that u're asking. Ofcourse u might be using a Curosr, so use clauses DESC & OPTIMIZE FOR n ROWS assuming you will give a proper primary key values. The same can be done for first 5 rows and programatically maniplulate 3 & 5 th row. But 3rd & 5th row manipulation kinda strikes me odd. It doesn't really happen that way. Can you elaborate a bit on what you're trying to do? Hope this helps. |
|
Back to top |
|
|
|