LIMIT in SQL
What is Limit Clause in SQL?
A Limit clause is commonly used in SQL when dealing with large datasets to limit the number of records that are returned from the SELECT statement.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
How to Use the Limit Clause in SQL?
Limit clauses are often used nested inside a SELECT statement, and the only purpose they satisfy is to return the specified number of records only.
The syntax for the same is given below.
The parameter in the above SELECT statement is number_rows, which is the limiting number of rows it is expected to return.
Example of Limit Clause in SQL
Consider the example table below:
| ID | Name | Salary |
|---|---|---|
| 1 | Ram | 50000 |
| 2 | Shyam | 40000 |
| 3 | Mohan | 58000 |
| 4 | Kishan | 10000 |
| 5 | Mahesh | 23000 |
| 6 | Dinesh | 45000 |
| 7 | Amit | 99000 |
| 8 | Jatin | 87000 |
Let's say we want the top 6 records to be selected from this table, the limit clause, along with the SELECT statement, will help us achieve it.
The result of the following select statement is given below.
| ID | Name | Salary |
|---|---|---|
| 1 | Ram | 50000 |
| 2 | Shyam | 40000 |
| 3 | Mohan | 58000 |
| 4 | Kishan | 10000 |
| 5 | Mahesh | 23000 |
| 6 | Dinesh | 45000 |
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
What is a Select LIMIT Statement, its Syntax, and Parameter Values?
As the name suggests, a SELECT limit statement is a standard statement with a LIMIT clause added to it, which is aimed at limiting the number of records selected.
The syntax for the same is given below.
The number_rows parameter can have any positive integer value.
What are the Advantages of the LIMIT Clause in SQL?
According to the LIMIT clause, only the maximum number of rows is included in the result collection. No additional rows are returned that satisfy the question collection condition, which saves us time and memory.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Learn More
Conclusion
- LIMIT in SQL is useful for selecting a specific number of rows from the table.
- It is used inside a SELECT statement.
- It can also be followed by clauses like ORDER BY which will give the ordered result for a specified number of rows.