Select next row from the table

IBM's flagship relational database management system

Select next row from the table

Postby Namrata Kalghatgi » Fri Oct 31, 2008 8:11 pm


I have a requirement in which i want to select a row and the next row of the row which satisfies a particular condition.

For example

Table 1:

Col1 Col2 Col3 Col4
Row1 1 abc 11 xyz
Row2 2 def 22 uvw
Row3 3 ghi 11 rst
Row4 4 jkl 33 opq

Now my requirement is to select Row2 and Row1 when Row1 satisfies the condition, or Select Row2 and Row3 when Row2 satisfies the condition.

In case the the query is

Select * From table 1 where C0l3 = 11;

The i shud select Row1 and Row2 and also Row3 and Row4.

Can anyone tell me a query for this.

Is there any way other than using a cursor?
Namrata Kalghatgi
Posts: 5
Joined: Thu Jul 31, 2008 6:41 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Select next row from the table


Re: Select next row from the table

Postby dick scherrer » Sat Nov 01, 2008 1:12 am


You should use a cursor.
Hope this helps,
User avatar
dick scherrer
Global moderator
Posts: 6308
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 90 times

Return to DB2


  • Related topics
    Last post