I can't find a clear answer for this anywhere in [MySQL documentation](http://dev.mysql.com/doc/).

When I run a query, something like:

*Code Block 1*

```
$stmt = $db->prepare('SELECT id, name FROM table WHERE status=1');

```

does the search start at the beginning of the table, at `row 0` (or the lowest available row)?

What I'm trying to do is go through a table one row at a time, and then exit when I get to the end:

*Code Block 2*

```
$curRow = 0;

while(true){
    $stmt = $db->prepare('SELECT id, name FROM table WHERE status=? AND id>? LIMIT 1');
    $stmt->execute(array(0, $curRow));

    $result = $stmt->fetchAll();

    if(count($result)){
        $curRow = $result[0]['id'];

        $stmt2 = $db->prepare('UPDATE table SET status=? WHERE id=?');
        $stmt2->execute(array(1, $curRow));

        ... do some other stuff ...
    }else{
        exit();
    }
}

```

And so far, in testing, this has worked exactly as intended. But will it always be so?

**Possible erroneous case:**

Start out with the following table:

```
table

id | name | status
-- | ---- | ------
 1 |  ... |   0
 2 |  ... |   0
 3 |  ... |   0
 4 |  ... |   0
 5 |  ... |   0
 6 |  ... |   0

```

And run the query in *Code Block 2*. Say it starts at the first row, so now we have `$curRow=1`, and the table looks as follows:

```
table

id | name | status
-- | ---- | ------
 1 |  ... |   1
 2 |  ... |   0
 3 |  ... |   0
 4 |  ... |   0
 5 |  ... |   0
 6 |  ... |   0

```

All is well. The code does whatever it needs to, and then continues with the loop. *Any* of the remaining rows will satisfy the conditions in `$stmt` (i.e. `status=0` and `id>$curRow`).

Will the statement always look at consecutive rows when checking the conditions? If not, it could end up at any arbitrary row, say the third:

```
table

id | name | status
-- | ---- | ------
 1 |  ... |   1
 2 |  ... |   0
 3 |  ... |   1
 4 |  ... |   0
 5 |  ... |   0
 6 |  ... |   0

```

And now we have `$curRow=3`, which means the query will *never* go back and look at the second row.

I know it's tricky business speaking in absolutes (always, never, every time, ...), but is there a way to ensure that the query begins at the lowest available row? Or does MySQL handle this automatically?