Home > Database > Mysql Tutorial > mysql用limit代替top_MySQL

mysql用limit代替top_MySQL

WBOY
Release: 2016-06-01 13:37:32
Original
1208 people have browsed it

bitsCN.com


mysql用limit代替top

 

mysql 中不支持top,而是用limit代替 

若要查询前10条记录,mysql用limit 10 

 

LIMIT可以实现top N查询,也可以实现M至N(某一段)的记录查询,具体语法如下: 

SELECT * FROM MYTABLE 

ORDER BY AFIELD 

LIMIT offset, recnum 

 

其中offset为从第几条(M+1)记录开始,recnum为返回的记录条数。例: 

select * from mytable 

order by afield 

limit 2, 5 

 

即意为从第3条记录开始的5条记录。
 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template