数据库:SQL分页? [英] Database: SQL Pagination?
本文介绍了数据库:SQL分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MySQL。
I'm using MySQL.
我想限制从数据库中获取的行数。我有一条SQL语句,返回与搜索相关的10,000条记录。
I want to limit the amount of rows fetched from the database. I have a SQL statement that returns 10,000 records which are all relevant to the search.
SELECT colA, colB, colC
FROM xyzTable
WHERE ...
ORDER BY colA
我知道使用TOP语句返回TOP x已获取的行数,但是如何获取搜索结果中间的行,例如50-100行?
I know how to use the TOP statement to return the TOP x number of rows fetched but how do I fetch rows rows in the middle of the search result, for example, rows 50-100?
推荐答案
MySQL的 limit子句使此操作变得容易:
MySQL's limit clause makes this easy:
SELECT cols
FROM table
LIMIT offset, rowcount
在您的情况下:
LIMIT 49, 50 -- skip rows 0-49, grab the next 50
这篇关于数据库:SQL分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文