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
 

 

How to retrieve first row in a table in efficient way ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Thu Jul 05, 2007 8:49 pm    Post subject: How to retrieve first row in a table in efficient way ?
Reply with quote

Hi ,

Can any body suggest me to retrieve the first row from a table in efficient way.

Thanks,
pavan
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Jul 05, 2007 9:37 pm    Post subject:
Reply with quote

Hello,

What is meant by "first row"?

Sequential files have a first and last record, but databases do not have the same.

Keep in mind that most database processing is done via one or more keys. There is no "first".
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Thu Jul 05, 2007 9:42 pm    Post subject:
Reply with quote

Pavan,

This can be one way:

Code:
SELECT * FROM table Name
FETCH FIRST ROW ONLY       
WITH UR;                   
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Jul 05, 2007 10:09 pm    Post subject:
Reply with quote

Hello,

That will fetch one record - not sure i understand how that would be "the first row from a table" icon_confused.gif . It would be the first row that particular query fetches, but that does not imply the first row in the table.

As i mentioned earlier, until what "first row" really means is defined, there is no way to read it and besides, there is not a "first row in the table" concept in most database systems.
Back to top
View user's profile Send private message
aryanpa1

New User


Joined: 26 May 2007
Posts: 45
Location: Chennai

PostPosted: Thu Jul 05, 2007 11:19 pm    Post subject:
Reply with quote

Hi Anuj ,

It worked. Thankyou...
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Fri Jul 06, 2007 6:00 am    Post subject:
Reply with quote

Code:

SELECT * FROM table Name
FETCH FIRST ROW ONLY       
WITH UR;   


Is extremely useless. You just arbitrarily selected a row. It could be different the next time you do it, or it could be the same for the life of the table.

This is a complete waste of a query without a ORDER BY clause.
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 -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Data replication from multiple Db2 ta... kishpra DB2 5 Mon Mar 27, 2017 9:58 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm
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 Efficient sorting chandracdac DFSORT/ICETOOL 5 Sat Oct 22, 2016 3:23 am


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