mySQL Super-tip! Use LIMIT and OFFSET to paginate your SELECT statements!

| No Comments »

Awesome, it seems that mySQL now supports the OFFSET clause.

This is very useful for paginating your SQL statements.

The following will return the first 10 entries of your select statement:

“SELECT field FROM table LIMIT 10”

This, on the otherhand, will OFFSET your result by 10, selecting your entries #10-20:

“SELECT field FROM table LIMIT 10 OFFSET 10”

Here’s an example of how to capture entries #10-30:

“SELECT field FROM table LIMIT 20 OFFSET 10”

Things just keeps on getting easier and easier!

Leave a Reply