Duplicate sorting data in Oracle paging Query

Source: Internet
Author: User
In the project development process, a large number of paging queries are used. When you want to sort data by date, a lot of duplicate data appears. This problem occurs because the date value is not unique in the data. We know that Oracle does not perform any sorting operations for paging queries, and Oracle reads the qualified numbers from data blocks sequentially.

In the project development process, a large number of paging queries are used. When you want to sort data by date, a lot of duplicate data appears. This problem occurs because the date value is not unique in the data. We know that Oracle does not perform any sorting operations for paging queries, and Oracle reads the qualified numbers from data blocks sequentially.

In the project development process, a large number of paging queries are used. When you want to sort data by date, a lot of duplicate data appears. This problem occurs because the date value is not unique in the data. We know

Oracle does not perform any sorting operations on the paging query. Oracle reads the qualified data from the data block sequentially and returns the data to the client. Oracle sorting algorithms are not stable. That is to say

Data, this algorithm does not guarantee that the data with the same key value is in the order before sorting.

To solve this problem, add a unique column, such as the primary key.

Select * from

(

Select a. *, rownum rn from

(Select * from user u order by u. createdate desc, u. id desc)

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.