|
|
| Author |
Message |
nareshb6
New User
Joined: 03 Mar 2005 Posts: 5
|
|
|
|
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 |
|
 |
References
|
|
 |
sireesha.m
New User
Joined: 14 Apr 2005 Posts: 1
|
|
|
|
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 |
|
 |
ankyhunk
Moderator
Joined: 05 May 2005 Posts: 102 Location: Navi Mumbai, India
|
|
|
|
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 |
|
 |
markanthos
New User
Joined: 28 Apr 2005 Posts: 14 Location: India
|
|
|
|
| if a table has 5 records and i want to extract the contents of 3rd record wht query will u use? |
|
| Back to top |
|
 |
Aditya Bhardwaj Warnings : 1 New User
Joined: 02 Nov 2004 Posts: 18 Location: Noida, India
|
|
|
|
| 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 |
|
 |
subhasis_50
Moderator
Joined: 09 Mar 2005 Posts: 367 Location: Earth
|
|
|
|
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 |
|
 |
Aditya Bhardwaj Warnings : 1 New User
Joined: 02 Nov 2004 Posts: 18 Location: Noida, India
|
|
|
|
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 |
|
 |
subhasis_50
Moderator
Joined: 09 Mar 2005 Posts: 367 Location: Earth
|
|
|
|
Hi Aditya,
You are correct. |
|
| Back to top |
|
 |
|
|