Use the LIMIT condition to restrict the number or records returned

For example to display the first 5 records that meet a query:
mysql> SELECT * FROM employee LIMIT 5;

To retrieve the rest of the records in batches we can also specify a point before the number or rows to return
SELECT FROM LIMIT , So to return rows 6-10 we would specify the start point of 5 and then ask to return 5 records.
mysql> SELECT * FROM employee LIMIT 5, 5;

Limit query to start at rows 3-7
mysql> SELECT * FROM employee LIMIT 2, 4;

Random order
SELECT * FROM tbl_name ORDER BY RAND();

ORDER BY RAND() combined with LIMIT is useful for selecting a random sample from a set of row
mysql> SELECT * FROM employee ORDER BY RAND() LIMIT 5;

Get the Row Holding the Maximum of a Certain Column by sorting descending by price and get only the first row using LIMIT clause
mysql> -> -> -> SELECT id, first_name FROM employee ORDER BY salary DESC LIMIT 1;

Sign up to vote on this title
UsefulNot useful