💻
notes
  • Initial page
  • sql
    • date-and-time
    • Ordering Columns
    • Replacing Portions of Text
    • count-rows
    • Changing the Case of Strings
    • Create Excerpts with Substring
    • Transactions
    • removing-data
    • Finding Length of Strings
    • add-row-to-a-table
    • limit-and-paginate-results
    • Concatenating Strings
    • SQL JOINs
    • basic-math
    • updating-rows-in-a-table
    • Subqueries
    • Set Operations
    • SQL Basics Cheatsheet
  • ruby
    • gems
      • Auto use Ruby version with gemset
      • Must Have Gems
      • Create Devise user without any validation
    • rails
      • What are the differences between #where and #find?
  • postgresql
    • Export database dump from Heroku and import to local database
  • glossary
  • vim
    • Edit Recorded Macros
    • Sort Multiple Lines
    • Search and Replace
    • Folding
  • iTerm
  • git
    • Git
  • Command Line Utilities
  • How To Use Notes
  • Terminal Cheatsheet for Mac
Powered by GitBook
On this page
  • Limiting Results
  • SQLite, PostgreSQL and MySQL
  • MS SQL
  • Oracle
  • Paging Through Results
  • SQLite, PostgreSQL and MySQL
  • MS SQL and Oracle

Was this helpful?

  1. sql

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.

SELECT <columns> FROM <table> LIMIT <# of rows> OFFSET <skipped rows>;
SELECT <columns> FROM <table> LIMIT <skipped rows>, <# of rows>;

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.

SELECT <columns> FROM <table> OFFSET <skipped rows> ROWS FETCH NEXT <# of rows> ROWS ONLY;
Previousadd-row-to-a-tableNextConcatenating Strings

Last updated 5 years ago

Was this helpful?