Selection restriction, LIMIT operator
The LIMIT operator allows you to extract a specific a range of records from one or more tables.
General query structure with the LIMIT operator
Comma syntax:
SELECT table_fields FROM table_name LIMIT [number_of_skipped_records,] number_of_records_to_output;
OFFSET syntax:
SELECT table_fields FROM table_name LIMIT number_of_records_to_output [OFFSET number_of_skipped_records];
If you do not specify the number of skipped records, they will be counted from the beginning of the table.
SELECT table_fields FROM table_name LIMIT number_of_records_to_output [OFFSET number_of_skipped_records];
If you do not specify OFFSET, they will be counted from the beginning of the table.
Examples
Let's take a Company table:
To output lines 3 to 5, you need to use this request:
SELECT * FROM Company LIMIT 2, 3;
Or what's the same thing:
SELECT * FROM Company LIMIT 3 OFFSET 2;
SELECT * FROM Company LIMIT 3 OFFSET 2;
The query returns the following selection:
This query skips the first two rows of the table (1, 2), and then outputs the next three entries (3, 4, 5).
Now try it yourself ⚡️
SELECT * FROM Company
LIMIT 3 OFFSET 2
Number of skipped records
Number of records to output
Select the rows of the table to see how the query is changing ⚡