我无法弄清楚为什么会这样。我有一个包含以下列的表:
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| adid | int(11) | NO | PRI | NULL | auto_increment |
| price | float | YES | | NULL | |
| categoryid | int(11) | YES | | NULL | |
| visible | tinyint(4) | YES | MUL | NULL | |
+-------------+------------+------+-----+---------+----------------+
此表中有7条记录可见且类别设置为3.我做了一个简单的查询:
SELECT adid FROM ads as a
WHERE categoryid = 3
and visible = 1
order by price desc
limit 0, 5
我得到以下adid的回复:1,4,3,15,7
在下一页上,查询是:
SELECT adid FROM ads as a
WHERE categoryid = 3
and visible = 1
order by price desc
limit 5, 5
我得到:11,15
也许我上得太晚了,但为什么我得到15次呢?
答案 0 :(得分:3)
要使结果稳定且一致,您需要有任何唯一的列参与排序。
在这种情况下,它可能是
ORDER BY price DESC, adid