limit-and-paginate-results

Limiting Results

SQLite, PostgreSQL and MySQL

To limit the number of results returned, use the LIMIT keyword.

SELECT <columns> FROM <table> LIMIT <# of rows>;

MS SQL

To limit the number of results returned, use the TOP keyword.

SELECT TOP <# of rows> <columns> FROM <table>;

Oracle

To limit the number of results returned, use the ROWNUM keyword in a WHERE clause.

SELECT <columns> FROM <table> WHERE ROWNUM <= <# of rows>;

Paging Through Results

SQLite, PostgreSQL and MySQL

To page through results you can either use the OFFSET keyword in conjunction with the LIMIT keyword or just with LIMIT alone.

MS SQL and Oracle

To page through results you can either use the OFFSET keyword in conjunction with the FETCH keyword. Cannot be used with TOP.

Last updated

Was this helpful?