In MySQL, after sorting by a field (ascending, descending), take one or several

We know that in ms sql server or access,
if you want to query the first 10 records, you can use top 10,
but this is not supported in mysql, it uses limit 10.
 
We can use a clause supported by SELECT in MySQL - LIMIT - to accomplish this function.
LIMIT can implement top N query, or M to N (a certain segment) record query. The specific syntax is as follows:
SELECT * FROM MYTABLE
ORDER BY AFIELD
LIMIT offset, recnum
where offset is the number of (M+1) records from which to start , recnum is the number of records returned. Example:
select * from mytable
order by afield
limit 2, 5
means 5 records starting from the 3rd record.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326667893&siteId=291194637