0

I am trying to paginate my page,

I am using this query :

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 10
) Where Rownum_ > 0

My result is

10662   1
11315   2
11142   3
13591   4
12344   5
12264   6
12186   7
11938   8
11183   9
10842   10

When i am trying to paginate in 5 max result solution is

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 5
) Where Rownum_ > 0

Result :

10662   1
11315   2
11142   3
11183   4
10842   5

And:

Select *
From   (
  Select Row_.*,
         Rownum Rownum_
  From   (
    Select Distinct(Qa.Question_Id) As Id
    From   Question Qa
    Where  Qa.Is_Deleted = 'F'
    And    Qa.Is_Answered = 'T'
    Order By Qa.Like_Count Desc
  ) Row_ 
  Where Rownum <= 10
) Where Rownum_ > 5

Result

12264   6
12186   7
11938   8
11183   9
10842   10

In second and third script, Solution in third script 9,10 rownum is equal with second script 4,5.

Why the solution is not like the first query? How can i paginate my query properly?

Jo_bast
  • 448
  • 1
  • 7
  • 19
  • Maybe the same question than [this](http://stackoverflow.com/questions/30321483/how-rownum-works-in-pagination-query)? – Aleksej Apr 18 '16 at 14:08
  • As an aside - `DISTINCT` is a keyword which applies across all columns that are selected and is **not** a function (as you appear to be formatting your code to try to make it appear to be). – MT0 Apr 18 '16 at 14:19
  • @Aleksej Not a duplicate as the linked question is asking how to do pagination (and several other clarifications about `ROWNUM` which would have been better separating into different questions) whereas this one is asking "Why is it not working after using what is the accepted method is that linked question?". – MT0 Apr 18 '16 at 14:42
  • @MT0 , i solved my issue like this -> Order By Qa.Like_Count Desc, qa.id. Qa.id is uniqe and it is ordering without any problem. Thanks a lot for help. – Jo_bast Apr 19 '16 at 14:53

0 Answers0