最近在使用mysql 分页查询数据的时候发现返回的数据与预期的不同,显示数据重复错乱。html
在官方文档 有这样一句话mysql
If multiple rows have identical values in the
ORDER BY
columns, the server is free to return those rows in any order, and may do so differently depending on the overall execution plan. In other words, the sort order of those rows is nondeterministic with respect to the nonordered columns.sqlOne factor that affects the execution plan is
LIMIT
, so anORDER BY
query with and withoutLIMIT
may return rows in different orders. Consider this query, which is sorted by thecategory
column but nondeterministic with respect to theid
andrating
columns: 数据库
说明当order by 列中有重复值的时候,mysql server 会看本身心情随机处理返回结果。ide
当使用mysql 进行分页查询出现数据不一致问题时候 能够看看order by 后面列数据是否有重复值this
参考文献:数据库内核月报 - 2015 / 06code