Limit SQL query result in MySQL

前端 未结 7 1639
無奈伤痛
無奈伤痛 2021-02-08 16:10

I would like to limit the amount of rows I fetch in MySQL. Can you show me how?

ex:

  • 1st query I would like to retrieve only the first 10,000 records
  • <
7条回答
  •  孤城傲影
    2021-02-08 17:01

    The term you're looking for is "pagination." Unfortunately, this is done differently depending on the SQL engine.

    For MS SQL Server, see this Stack Overflow question.

    Since you mentioned MySQL, it's actually quite simple:

    SELECT [columns] FROM [a table] LIMIT 10000
    SELECT [columns] FROM [a table] LIMIT 10000 OFFSET 10000
    

    The first statement fetches results 1-10,000, and the second statement fetches results 10,001-20,000.

提交回复
热议问题