Oracle paging query sorting data duplication problem

Source: Internet
Author: User

In the process of project development, a large number of use of paging query, when you want to let the data sorted by date, there are many duplicate data appear. The cause of this problem is that in the data, the value of the date is not unique. We know

Oracle paged queries are not doing any sort operations, and Oracle is sequential to read the eligible data from the data block back to the client. Oracle's sort algorithm does not have stability, that is, for key values equal to the

Data, which, when sorted, does not guarantee that the data of these key values is equal to the order in which they were sorted.

The solution to this problem is to add a uniqueness column, such as a primary key, to solve the problem.

SELECT * FROM

(

Select A.*, RowNum rn from

(SELECT * from user ' u order by u.createdate desc, u.id desc) A

where RowNum <=20

) b

where B.rn >=0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.