LIMIT Clause

The LIMIT clause limits the number of data records that are displayed in the result set of a search query. It contains the following properties:

  1. OFFSET: OFFSET defines the starting index of the result, i.e., the first record’s position that will be displayed in the result.
  2. VALUE: VALUE defines the number of records to be retrieved from the starting index, i.e., the OFFSET.

The LIMIT clause identifies the OFFSET index and then displays the number of records as specified in the VALUE from the OFFSET index. You can also just specify the value without specifying the offset, when the starting index is the first record.

The LIMIT clause is only used when a specific number of records is to be displayed. It is used towards the end of the query after all the other clauses and statements.

The basic syntax for using the LIMIT clause with a SELECT statement is:

    
copy
SELECT column_name(s) FROM parent_table_name LIMIT OFFSET, VALUE

Example:

To view a list of the movies from the Movies table consisting of up to three records from the second starting index execute the following query:

    
copy
SELECT * FROM Movies LIMIT 1,3

It will generate the following output:

MovieID MovieName ShowDate ShowTime TheaterID
2057 Ant-Man and the Wasp 2018-07-13 14:20:00 052
2058 Hotel Transylvania 3: Summer Vacation 2018-07-14 17:00:00 052
2059 Skyscraper 2018-07-14 21:30:00 053

Last Updated 2023-08-28 18:12:09 +0530 +0530

ON THIS PAGE