Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
DB2 Interview Queries

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions
Author Message
nareshb6

New User


Joined: 03 Mar 2005
Posts: 5

PostPosted: Tue Mar 22, 2005 10:41 am    Post subject: DB2 Interview Queries
Reply with quote

1. How to retrive nth row from particular table.

2. differenc between spaces and nulls in DB2?

3.Can we give spaces or null in secondry key r ?why?
Back to top
View user's profile Send private message
References
sireesha.m

New User


Joined: 14 Apr 2005
Posts: 1

PostPosted: Thu Apr 14, 2005 5:00 pm    Post subject: Re: DB2 Interview Queries
Reply with quote

1. How to retrive nth row from particular table.

Ans: select * from tab1 where n=(select count(*) from tab1)

2. differenc between spaces and nulls in DB2?

Ans:Space means it is a space character but null means it is not a space or zero it is some junk value filled by the system if you have not entered any value in to the field.

3.Can we give spaces or null in secondry key r ?why?
Ans: ya null is allowed in alternate key
Back to top
View user's profile Send private message
ankyhunk

Moderator


Joined: 05 May 2005
Posts: 102
Location: Navi Mumbai, India

PostPosted: Mon May 09, 2005 1:00 pm    Post subject:
Reply with quote

Hi sireesha.m,
I think yr answer to the first query is wrong. The Stmt which u ve given might fetch the last record of a table.
Back to top
View user's profile Send private message
markanthos

New User


Joined: 28 Apr 2005
Posts: 14
Location: India

PostPosted: Tue May 10, 2005 11:48 am    Post subject: DB2 Question.
Reply with quote

if a table has 5 records and i want to extract the contents of 3rd record wht query will u use?
Back to top
View user's profile Send private message
Aditya Bhardwaj
Warnings : 1

New User


Joined: 02 Nov 2004
Posts: 18
Location: Noida, India

PostPosted: Thu May 19, 2005 2:29 pm    Post subject: Re: DB2 Question.
Reply with quote

markanthos wrote:
if a table has 5 records and i want to extract the contents of 3rd record wht query will u use?


It's hard to fetch a record at a partivular position in the table without using the associated Primary Key for that particular record. The other only solution apparently fix here is to fetch first 3 records out of 5 (as in the example of markanthos) and then use the query given by sireesha.m.
Though here we can do this, but for very large and heave tables this is not at all a feasible solution, you must know the key to access a particular record.
Back to top
View user's profile Send private message
subhasis_50

Moderator


Joined: 09 Mar 2005
Posts: 367
Location: Earth

PostPosted: Thu May 19, 2005 3:28 pm    Post subject:
Reply with quote

Hi,
You can use the following query to get 3rd row from your table BY USING the row count function.
SELECT * FROM TABLE1 WHERE ROWCOUNT = 3
Back to top
View user's profile Send private message
Aditya Bhardwaj
Warnings : 1

New User


Joined: 02 Nov 2004
Posts: 18
Location: Noida, India

PostPosted: Thu May 19, 2005 4:34 pm    Post subject:
Reply with quote

Hi Subhasis,
According to me the query given by you "SELECT * FROM TABLE1 WHERE ROWCOUNT = 3" is correct only in case if ROWCOUNT is some field that contaings the Serial_ID of the Table, as after WHERE clause we have to give the column name and giving "ROWCOUNT=3", means "ROWCOUNT" is some field name.
In DB2, a table can not be defined without Serial_ID, which most probably be the very first column of the table and contains the serial numbers corresponting to the rows. So to make this query true and working we have to make ROWCOUNT a field_name containing the serial number in ascending order, to fetch the 3rd row of the table.

e.g. if we say we have a table called TABLE1 with column name TABLE1_ID, containing the serial numbers of rows existing, then the following query will fetch the 3rd row of the table:-


SELECT * FROM TABLE1 WHERE TABLE1_ID = 3;
Back to top
View user's profile Send private message
subhasis_50

Moderator


Joined: 09 Mar 2005
Posts: 367
Location: Earth

PostPosted: Thu May 19, 2005 5:11 pm    Post subject: Re: DB2 Interview Queries
Reply with quote

Hi Aditya,
You are correct.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Interview Questions All times are GMT + 6 Hours
Page 1 of 1