Click to See Complete Forum and Search --> : Begin a select at a certain row


Nibinaear
November 22nd, 2006, 08:16 AM
Is there any way you can start a select statement at a certain row but include other rows after that as well? I don't mean using the limit command. What I mean is:

You have 10 rows in your table and 2 attributes:

id | cursor |
1 | 0 |
2 | 0 |
3 | 0 |
4 | 0 |
5 | 1 |
6 | 0 |
7 | 0 |
8 | 0 |
9 | 0 |
10 | 0 |

select *
from adverts
where id=5
and cursor=1

But include 4 more rows after that for example. At the moment, if I say where cursor=1 then I only get row 5 back.

Shuja Ali
November 23rd, 2006, 01:23 AM
This will show all the rows after id 5.
Select * From ADVERTS Where id >=5

Nibinaear
November 24th, 2006, 09:42 AM
That won't work because as soon as you say where ad_cursor=1 you're left with only one row again.

I actually had to use a seperate query to find where the results would start and then use between to get back where between 1 and 5 etc.

Shuja Ali
November 25th, 2006, 03:14 AM
Well the query that I have shown above will display all records after id = 4. Probably I didn't understand the requirements properly.

Alsvha
November 27th, 2006, 01:27 AM
That won't work because as soon as you say where ad_cursor=1 you're left with only one row again.

I actually had to use a seperate query to find where the results would start and then use between to get back where between 1 and 5 etc.

If I understand you correct, you want the row, and all subsequent rows, from your "cursor" location?

Then the most simple way will be to just make a subquery; something along the line of:
select *
from adverts
where id >= (select id
from adverts
where cursor=1)