Incorrect data duplication for Oracle paging data

Source: Internet
Author: User


Oracle General pagination is written as

Select A.id,a.title,rownum as Rn,a.create_time from (select A.* to temp a order by create_time Desc) A Where rownum<=20

Note: I'm using create_time to sort the create_time with equal

In order to vary the score page data I use the LEFT join to see if the data is normal

This is a page I used to correlate the difference between a score of 20 data and 10 of the data

Select A.title,a.rn,b.title,b.rn from (select A.id,a.title,rownum as Rn,a.create_time from ( Select A.* from Temp a order by create_time Desc) a where rownum<=20) a LEFT join (select A.id,a.title,row  Num as Rn,a.create_time from (select A.* from temp a order by create_time Desc) a where rownum<=10) B on A.id=b.id

Execution results

According to the truth, the right front 10 will be the same as the left Front 10 data, but after the operation is not the same

as If that happens, there may be a record in the paging clock that appears on multiple pages or even multiple page data

SQL adjusted in a nested layer

Select A.* from (select A.id,a.title,rownum as Rn,a.create_time from (select A.* from Temp a ORDER BY create_time Desc) a) a where a.rn<=20
select a.title,a.rn,b.title,b.rn from     (select a.* from              (Select a.id,a.title,rownum as rn, a.create_time from                      (select a.* from temp a order by create _TIME&NBSP;DESC)  a)  a  where a.rn<=20)  a   left join     (select a.* from              (select a.id,a.title,rownum as rn,a.create_time from                      (select a.* &NBSP;FROM&NBSP;TEMP&NBSP;A&NBSP;ORDER&NBSP;BY&NBSP;CREATE_TIME&NBSP;DESC)  a)  a  where  a.rn<=10)  b  on a.id=b.id 

Comparison of execution results

So the result is right.


There is no discovery although the same sq set up a layer of select after the result set is changed before and after two pictures of the left column results are not the same



Summarize the time I use here to sort a lot of data with equal time if the sort field alone should not have this problem appearing




Incorrect data duplication for Oracle paging data

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.