1

I have a simple table:

ID    |     Name
0183        namez
2543        etc
2654        etc
4364        namez
3246        namey
3745        namew
3464        namem
7524        etc
2459
2457
0845
9325

I need to be able to select the 6th thru 10th rows or the 4th thru 25th or whatever, so that I can select only the rows that I need without using any kind of Id column, also it's alway Xth "thru" Yth, because I'm not hardcoding an column names here, I can't use order by but have to use natural order. Is this even possible? Thanks for any help.

4

3 回答 3

4

您需要将一个LIMIT子句传递给您的SELECT查询。在 MySQL 中,这将是:

SELECT * FROM simpletable LIMIT 5, 5;

笔记:

  • 第一个数字是偏移量,它需要是第一行减一,(即 6 - 1)。
  • 第二个是返回的行数,这需要是最后一行 - 偏移量(即 10 - 5)。

参见:http ://dev.mysql.com/doc/refman/5.0/en/select.html

于 2013-07-12T02:25:20.660 回答
-1

您可以执行以下操作:

SELECT * FROM tables ORDER BY ID LIMIT 4, 10
于 2013-07-12T02:20:22.897 回答
-1
SELECT *
FROM tables
ORDER BY ID
LIMIT 5, 5
于 2013-07-12T02:22:33.557 回答