SQL Limiting Rows Returned

Example code for various database systems showing how to limit the result set...

Oracle

Limit to 100 rows...

SELECT *

  FROM myTable

WHERE ROWNUM < 101;

MySQL

Limit to 100 rows...

SELECT *

  FROM myTable

LIMIT 100;

Limit to 100 rows skipping the first 50 rows...

SELECT *

  FROM myTable

LIMIT 49,100;

or (using PostgreSQL compatible syntax in MySQL)...

SELECT *

  FROM myTable

LIMIT 100 OFFSET 49;

Select the last 10 rows...

SELECT *

  FROM myTable

 ORDER BY mydate DESC

 LIMIT 10;

Bibliography