PostgreSQL – 从LIMIT OFFSET重复行
发布时间:2020-12-13 16:27:34 所属栏目:百科 来源:网络整理
导读:我在分页的记录集中注意到一些重复的行. 当我运行这个查询: SELECT "students".* FROM "students" ORDER BY "students"."status" asc LIMIT 3 OFFSET 0 我得到: | id | name | status | | 1 | foo | active | | 12 | alice | active | | 4 | bob | active
我在分页的记录集中注意到一些重复的行.
当我运行这个查询: SELECT "students".* FROM "students" ORDER BY "students"."status" asc LIMIT 3 OFFSET 0 我得到: | id | name | status | | 1 | foo | active | | 12 | alice | active | | 4 | bob | active | 下一个查询: SELECT "students".* FROM "students" ORDER BY "students"."status" asc LIMIT 3 OFFSET 3 我得到: | id | name | status | | 1 | foo | active | | 6 | cindy | active | | 2 | dylan | active | 为什么“foo”出现在这两个查询中?
因为返回的所有行具有与状态列相同的值.在这种情况下,数据库可以按任意顺序返回行. 如果你想要一个可重复的排序,你需要添加一个第二列到你的order by语句使它一致.例如. ID列: SELECT students.* FROM students ORDER BY students.status asc,students.id asc 如果两行的状态列具有相同的值,则它们将按照id排序. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |