Sql - LIMIT and OFFSET
Code Life
By Pierre Marsaa
Introduction to LIMIT
The LIMIT clause in SQL is used to restrict the number of rows returned by a query. It's particularly useful when you only need to see a specific number of records instead of the entire result set.
Here's the basic syntax:
Loading editor...
Let's look at our Codémon table and try to get only the first 3 Codémons:
Loading data...
↗️
Loading editor...
↶
↷
This query returns only the first 3 rows from the result set.
Common LIMIT Use Cases
LIMIT is commonly used for:
- Retrieving the top N records (e.g., top 10 highest scores)
- Pagination (showing a limited number of results per page)
- Performance optimization (limiting results for large tables)
- Preview data (quickly seeing a sample of results)
Verify