What is the usage of limit and offset in SQL?

In SQL, LIMIT and OFFSET are two keywords used to restrict the number of rows in a query result and the OFFSET.

  1. LIMIT: is used to restrict the number of rows returned in a query. The syntax is LIMIT n, which indicates that the number of rows returned should not exceed n. For example, LIMIT 10 means that the number of rows returned should not exceed 10.
  2. OFFSET: Used to specify the offset of the returned result. The syntax is OFFSET n, which indicates that data should be returned starting from the nth row in the result set. For example, OFFSET 5 indicates that data should be returned starting from the 6th row in the result set.

Typically, LIMIT and OFFSET are used together to achieve pagination in queries. For example, LIMIT 10 OFFSET 20 indicates returning 10 rows of data starting from the 21st row, used for implementing pagination in queries.

bannerAds