Limit SQL query result in MySQL

2020-06-03 07:28发布

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
  • 2nd query I would like to retrieve only records from 10,000 - 20,000

etc

7条回答
我只想做你的唯一
2楼-- · 2020-06-03 08:25

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.

查看更多
登录 后发表回答