View previous topic :: View next topic
|
Author |
Message |
Gops
New User
Joined: 21 Jul 2005 Posts: 23
|
|
|
|
Hi Guys,
How do you retrive 1st row from a db2 table?
Regards,
Gops |
|
Back to top |
|
|
Mamata
New User
Joined: 01 Aug 2005 Posts: 4 Location: hyderabad
|
|
|
|
Hi,
U can fetch the 1st row of a DB2 table by executing the following query:
select * from TABLENAME fetch first row only;
Similarly, u can fetch the number of rows u wish by appending the No after 'first'.
Ex: select * from TABLENAME fetch first 50 rows only; will fetch first 50 rows from the table.
Regard,
Mamata. |
|
Back to top |
|
|
Gops
New User
Joined: 21 Jul 2005 Posts: 23
|
|
|
|
Hi Mamata,
Thanks for your valuable inputs. I have some more queries with the same topic.
1. Is there any way out to find the last row or last N rows from a db2 table?.
2. Can we retrive say 50th to 60th row from DB2 table?
3. And also is it possible to retrive the Nth row from DB2 table?
I hope you will be having answers to these questions.
Kind Regards,
Gops |
|
Back to top |
|
|
Mamata
New User
Joined: 01 Aug 2005 Posts: 4 Location: hyderabad
|
|
|
|
Hi,
u can try a query like this to get the Nth row of a table. u can get the Primary key for the row from this query and then can extract the row from that. here voucher_id is my PK. i am not sure about this, hope it works :)
this'll select the 2nd row of the table as the ROW#=2 here.
SELECT voucher_id, ROW# FROM pfsyuc.ps_voucher TB1,
TABLE (SELECT COUNT(*) + 1 AS ROW#
FROM pfsyuc.ps_voucher TB2
WHERE TB2.voucher_id < TB1.voucher_id) AS TEMP_TAB
WHERE ROW# = 2;
to get the last row, u can first get the count and then specify the row number in the above query.
Regards,
Mamata. |
|
Back to top |
|
|
Prasanthhere
Active User
Joined: 03 Aug 2005 Posts: 306
|
|
|
|
To retrieve from the 50 th row from a Db2 Table go 4 the following query
SELECT EMPNO, LASTNAME, FIRSTNME, SALARY
FROM TABLENAME
WHERE 50 > (SELECT COUNT(*)
FROM TABLENAME
WHERE A.SALARY > B.SALARY
AND B.SALARY IS NOT NULL)
ORDER BY SALARY; |
|
Back to top |
|
|
atik
New User
Joined: 29 Jul 2005 Posts: 20
|
|
|
|
what is A and B here? U have not specified A and B in the query right? |
|
Back to top |
|
|
|