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
SELECT table_fields FROM table_list LIMIT [number_of_missed_records,] number_of_records_to_output;
If you do not specify the number of skipped records, they will be counted from the beginning of the table.
The LIMIT operator is not implemented in all DBMS, e.g. MSSQL to output entries from the beginning of the table is used the TOP operator, but for those occasions when you need to make the offset from beginning of table, designed design OFFSET FETCH.
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;
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).
Tasks for self-testing
Nested SQL queries