How to retrieve n-th row ie n-th record of any table irrespective of the columns and the values present in the table without using ROWID(As it is not supported in DB@)?

Showing Answers 1 - 10 of 10 Answers

legacy

  • Mar 22nd, 2006
 

This could be logic if u want it in cobol program , U use FETCH FIRST N ROWS ONLY . here n can take values of desired row no.then u can loop thru cursor till end of row . for making N as user supplied u need to go for dynamic sql in which u ll build whole sql string .

or u can use cursor scrolling options in the fetch statement.

  Was this answer useful?  Yes

Siva Reddy

  • Mar 22nd, 2006
 

Declare a Cursor and fetch rows by descending. This will get the Nth row on First Instance. But Guess this Query degrades Performance

  Was this answer useful?  Yes

Culver_lake

  • Mar 23rd, 2006
 

Without getting too theoretical, there is no Nth row of a relation. There is no first row, no last row etc.  Order of the rows and columns are undefined concepts. 

In order to retrieve any row you need to have values that can be compared (ie retrieved via the equality relation). The fact that a column equals a value does not depend on order in a relational system.  Even system that support a pseudo column like row_number or something similar are equating values.

Ask yourself the question: how do I know I want the nth row without knowing previously what identifies it?

  Was this answer useful?  Yes

javid

  • Mar 27th, 2006
 

To retrieve the nth row from table you can code Query like

SELECT * FROM TABLE-NAME WHERE NTH=(SELECT COUNT(*) FROM TABLE WHERE COUNT >2)

IF WROUNGH FEED BACK ME

  Was this answer useful?  Yes

rajani

  • May 11th, 2006
 

sir EDid ,

 I dont understand the problem in asking for nth row of a table. we can simply ask for 10th row of a table ,and we can try to obtain it using the rownum value.

  like ---

    select * from emp where rownum = 10;

   whats wrong with this query???please suggest!!

     

   

  Was this answer useful?  Yes

Nahidullah Khan

  • Jun 1st, 2006
 

i think u can use following sql statement to retreive nth (5th for example) row of any table

select * from <table-name> where rrn(table-name) = 5

this command will work atleast on db2/400 sql

THANKS.

  Was this answer useful?  Yes

Shatadru

  • Jun 19th, 2006
 

This is a fallacious question. IN rdbms, by definition, there is no nth row, as the ordering of the rows is immaterial

  Was this answer useful?  Yes

kaviarasu

  • Jun 23rd, 2006
 

SELECT  *  FROM  TABLE_NAME  AA

WHERE  5 = (SELECT  COUNT (FIRST_FIELD) FROM TABLE_NAME

                     WHERE FIRST_FIELD <= AA.FIRST_FIELD )

WITH UR;

  Was this answer useful?  Yes

dyury

  • Mar 7th, 2010
 

We can use scrollable cursor ( with DB2 V8 and higher).

FETCH FIRST ROWSET STARTING AT ABSOLUTE N FROM CURSOR1 FOR 1 ROW.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Answer Question

Click here to Login / Register your free account


 
Send   Reset

 

Related Answered Questions

 

Related Open Questions