Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Retrival of 1st row from a table.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Retrival of 1st row from a table.
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    Post subject:
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    Post subject: Re: Retrival of 1st row from a table.
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    Post subject:
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    Post subject:
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    Post subject: Re: Retrival of 1st row from a table.
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm
No new posts Getting soc4 on internal table in cobol abdulrafi COBOL Programming 13 Fri May 06, 2016 3:39 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us