MySQL, orderby and limit paged data duplication

background

Read the rules are ordered by a table sequence field, and this field is filled out by hand the people. So, we can imagine, more than one data, the same value as the case may inevitably will appear.
As described above, might lead to the following two data overlap appears sql:

select * from table order by sequence(包含重复值的字段) limit 0,10
select * from table order by sequence(包含重复值的字段) limit 10,10

Explanation

From the Internet to find an explanation to this question the article is not elaborated here. Cause of the problem is roughly:

mysql5.6 optimizer to do an optimization, use the priority queue, and the 5.5 version does not appear.

The sense of taste can tap: https://segmentfault.com/a/1190000004270202

Solution

Solution I can think of two

1. Based on the available data

You can modify the sql statement order by fields. In the case does not affect the expected results of the sort the sql statement instead sorted by two dimensions:

select * from table order by sequence desc,id asc limit 0,10

2. Avoid manually fill the sort field

Because manually fill the sort field, it is not easy to avoid repetition of the value of the case, so just drag using jQuery plugin to sort, so that the rear end of the program to be sorted according to the order of the foreground display.
You can use jQuery List DragSort plug-learning tutorial seen when this plugin before, for everyone to share.

jQuery List DragSort plug-ins Tutorial

Guess you like

Origin www.cnblogs.com/luyuqiang/p/mysql-orderby-limit-may-get-troblems.html