MySQL LIMIT OFFSET
The LIMIT
clause restricts the number of records returned by a query, while OFFSET
specifies the number of records to skip. These are useful for paginating query results.
Examples with Tamil Kings
1. Limiting the Number of Records
SELECT * FROM tamil_kings_auto_increment LIMIT 5;
Code Explanation: This query retrieves the first 5 records from the tamil_kings_auto_increment
table.
2. Using LIMIT with OFFSET for Pagination
SELECT * FROM tamil_kings_auto_increment LIMIT 5 OFFSET 10;
Code Explanation: This query skips the first 10 records and returns the next 5 records from the tamil_kings_auto_increment
table.
Best Practices
- Use
LIMIT
andOFFSET
for paginating query results efficiently. - Combine with
ORDER BY
to ensure consistent result ordering.
Key Takeaways
LIMIT
restricts the number of records returned.OFFSET
specifies the number of records to skip before starting to return results.