LIMIT And OFFSET clause of SQL

Last updated: April 26, 2023

LIMIT clause is use for fetching limited number of records from database table. For example your database table have 10k records. If you fetch bulk data at a time, that takes lot of processing time. In that situation LIMIT query will help us.

Syntax:

SELECT column1, column2, column3, ..... FROM table_name LIMIT limiting_value;

According to this course, all data of contact table:

SELECT * FROM contact;

Using SQL LIMIT query with limiting value 5:

SELECT * FROM contact LIMIT 5;
Using SQL LIMIT query with limiting value 5

OFFSET clause is use to avoid numbers of records from table. OFFSET must work with LIMIT clause together.

Syntax:

SELECT * FROM table_name LIMIT limiting_value OFFSET offset_value;

Using SQL OFFSET query with limiting value 5 and offset value 5;

SELECT * FROM contact LIMIT 5 OFFSET 5;
Using SQL OFFSET query with limiting value 5 and offset value 5

Shorter syntax to limit and offset clause:

SELECT * FROM contact LIMIT 5, 5;
Shorter syntax to limit and offset clause

Related post