Thiyagarajan E

Thiyagarajan E

  • 829
  • 984
  • 114.8k

DENSE_RANK() Vs OFFSET in Sql?

Nov 10 2018 4:34 AM

which is the optimized way for server-side pagination in SQL using DENSE_RANK() or OFFSET?

OFFSET Query:

  1. SELECT * FROM Tbl_Employee OFFSET @PageSize * (@Page - 1) ROWS    
  2. FETCH NEXT @PageSize ROWS ONLY OPTION (RECOMPILE);  

DENSE_RANK():

  1. SELECT *
  2. FROM (  
  3.       SELECT DENSE_RANK() OVER (ORDER BY FullName ASCAS RowNo,*  FROM Tbl_Employee   
  4.  ) TAB  
  5. WHERE RowNo >= 1 and RowNo <= 10    
  6. ORDER BY 2 ASC;  


Answers (1)