SQL basic -> Limit number of records returned by SELECT

Condition in WHERE clause places filter on returned dataset. Additional option is to use "TOP" or "LIMIT" clause:

/* select 3 top paid employees */

/* MS-Access and TSQL syntax */
SELECT TOP 3 [EmpNo], [FirstName], [LastName], [Salary]
FROM Employees
WHERE Salary > 90000
ORDER BY Salary DESC;

/* MySQL syntax */
SELECT EmpNo, FirstName, LastName, Salary
FROM Employees
WHERE Salary > 90000
ORDER BY Salary DESC
LIMIT 0,3;


MySQL LIMIT clause have one or two numeric arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0.


sqlexamples.info