Three common forms of SQL paging

Source: Internet
Author: User



  1. --top not in mode
  2. Select Top Bar number * from tablename
  3. where Id not in (select Top Bar Number * page Id from tablename)
  4. --row_number () over () mode
  5. SELECT * from (
  6.     SELECT *, Row_number () over (Order by Id) as RowNumber from tablename
  7. ) as b
  8.   Where RowNumber between current page -1* number of pages and pages * Number of bars
  9. --offset FETCH Next Way
  10. --SQL2012 more than version support
  11. SELECT * FROM tablename
  12. ORDER by Id offset page row fetch Next number row only



Analysis: When the amount of data is large

Top not in mode: query data faster than before

Row_number () over () mode: query data faster than the previous one

Offset fetch Next method: Stable speed, better than the first 2, but the SQL version limit of 2012 and above to use

Three common forms of SQL paging

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.