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

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

WBOY
WBOYOriginal
2016-06-07 16:27:121378Durchsuche

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;
            
            

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

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

结果:
(注意红色部分)

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn