对于WordPress,我使用相同的源代码和相同的数据库,只是mysql版本不同。这使我的页码帖有重复之处。这是我发现的。知道怎么用更高的版本来解决吗?
这是针对第2页和第3页查询输出的。左边是MySql 5.5,右边是MySql 5.6.up_posts.ID是独一无二的。
SQL语句:-
SELECT SQL_CALC_FOUND_ROWS up_posts.ID FROM up_posts WHERE 1=1 AND up_posts.post_type = 'post' AND (up_posts.post_status = 'publish' OR up_posts.post_status = 'closed' OR up_posts.post_status = 'private' OR up_posts.post_status = 'hidden') ORDER BY up_posts.post_date DESC LIMIT 10, 10
SELECT SQL_CALC_FOUND_ROWS up_posts.ID FROM up_posts WHERE 1=1 AND up_posts.post_type = 'post' AND (up_posts.post_status = 'publish' OR up_posts.post_status = 'closed' OR up_posts.post_status = 'private' OR up_posts.post_status = 'hidden') ORDER BY up_posts.post_date DESC LIMIT 20, 10
第2页:-不同的限制是10,10
第3页:-不同的限制是20,10
似乎MySQL 5.5将按ID进行排序,但上面的5.6没有此功能。
发布于 2017-04-05 00:39:51
添加了ORDER BY up_posts.post_date DESC, up_posts.ID DESC
,不再重复结果。似乎我们需要手动添加这个以避免不必要的问题。
仅供参考。适用于MySQL 5.6和5.7。
如果要按主键排序,则必须显式地这样说。
https://dba.stackexchange.com/questions/169163
复制相似问题