IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Retrival of 1st row from a table.


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Gops

New User


Joined: 21 Jul 2005
Posts: 23

PostPosted: Mon Aug 01, 2005 12:10 pm
Reply with quote

Hi Guys,

How do you retrive 1st row from a db2 table?


Regards,
Gops
Back to top
View user's profile Send private message
Mamata

New User


Joined: 01 Aug 2005
Posts: 4
Location: hyderabad

PostPosted: Mon Aug 01, 2005 3:25 pm
Reply with quote

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
View user's profile Send private message
Gops

New User


Joined: 21 Jul 2005
Posts: 23

PostPosted: Mon Aug 01, 2005 3:56 pm
Reply with quote

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
View user's profile Send private message
Mamata

New User


Joined: 01 Aug 2005
Posts: 4
Location: hyderabad

PostPosted: Mon Aug 01, 2005 5:28 pm
Reply with quote

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
View user's profile Send private message
Prasanthhere

Active User


Joined: 03 Aug 2005
Posts: 306

PostPosted: Wed Aug 03, 2005 2:55 pm
Reply with quote

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
View user's profile Send private message
atik

New User


Joined: 29 Jul 2005
Posts: 20

PostPosted: Thu Aug 18, 2005 11:23 am
Reply with quote

what is A and B here? U have not specified A and B in the query right?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top