What does LIMIT do in SQL?
LIMIT in SQL is used to restrict the number of rows a query returns.
Syntax:
sql
SELECT Column1, Column2
FROM Table_Name
LIMIT N;Example:
sql
SELECT *
FROM Employees
LIMIT 5;What this query does
- Returns only the first 5 records from the
Employeestable. - The rest of the records are ignored.
Notes:
- Often paired with
ORDER BY, to pick, say, the top 5 by salary:
sql
SELECT Name, Salary
FROM Employees
ORDER BY Salary DESC
LIMIT 5;- Some DBMSs (PostgreSQL, MySQL) let you set an offset:
sql
LIMIT 5 OFFSET 10; -- pick 5 rows, skipping the first 10Put simply,
LIMITlets you control how many rows a query returns, which is handy for large tables or picking top results.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.