How do you return only the first 10 records?
To return only the first 10 records, the LIMIT keyword is used in SQL.
Example:
sql
SELECT *
FROM Employees
LIMIT 10;What this query does
- Returns the first 10 rows of the
Employeestable. - The rest of the records are ignored.
Tips:
- Usually paired with
ORDER BY, to define which records count as "first":
sql
SELECT *
FROM Employees
ORDER BY Age DESC
LIMIT 10;- Different DBMSs can also use
TOP(SQL Server):
sql
SELECT TOP 10 *
FROM Employees;Put simply,
LIMIT 10lets you pull just the first 10 records from a table, in the given order.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.