frostymarvelous
frostymarvelous

Reputation: 2805

mysql offset true behaviour

I'm creating a pagination with a where clause. I need to know the true behaviour of the offset.

  1. Is the offset calculated based on all the rows that match the where clause? Or
  2. The offset is calculated like an id and all rows are considered. Eg. If you specify an offset of 5, rows will be returned starting from the 6th row in the table even of the first 4 rows don't match the where clause?

Edit: I want to be sure since the second behaviour would be totally incorrect and cause problems. Thanks for your answers. I can't comment as my browser fails at javascript and ajax horribly.

Upvotes: 0

Views: 314

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191779

Are you talking about using the LIMIT clause? LIMIT puts a cap on the number of successful matches, not the total matches. The offset portion of limit is calculated from the matches rather than all eligible rows. MySQL will not necessarily scan rows in a given order and may not scan some rows at all, so it wouldn't short change you rows if a failed match had a lower index.

Upvotes: 1

Harry Joy
Harry Joy

Reputation: 59670

Yes the offset is calculated based on all rows that matches the where clause. Just try it.

Upvotes: 4

Related Questions