Home > Database > Mysql Tutorial > mysql带条件进展分页查询时必须对数据排序

mysql带条件进展分页查询时必须对数据排序

WBOY
Release: 2016-06-07 16:27:12
Original
1451 people have browsed it

mysql带条件进行分页查询时必须对数据排序 使用mysql进行分页查询时,如果sql语句有where条件,必须使用order by ,不然会出错的,切记!! ? 如果没有where条件,mysql会采用默认的物理排序,不会出错,但为了万无一失,最好加上order by,不过会有性能损失

mysql带条件进行分页查询时必须对数据排序

使用mysql进行分页查询时,如果sql语句有where条件,必须使用order by ,不然会出错的,切记!!

?

如果没有where条件,mysql会采用默认的物理排序,不会出错,但为了万无一失,最好加上order by,不过会有性能损失哦!


查第一页的语句

SQL code
SELECT*FROM article a where a.type in (1,2,4) limit 0,20;
            
            
Copy after login
Copy after login

第一页的结果
(注意红色部分)
第二页的语句

SQL code
SELECT*FROM article a where a.type in (1,2,4) limit 20,20;
            
            
Copy after login
Copy after login

结果:
(注意红色部分)

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