如何在表格中间选择一行并选择之后的所有行?

时间:2013-12-18 16:30:33

标签: php mysql sql

当我想从最后一行选择数据库的第一行时,我使用SELECT * FROM Gallery ORDER BY ID DESC,但我想选择从最后到第一行的第三行,例如这段代码:

$LastRowID = 20;

$FindRows = mysqli_query($Database,"SELECT * FROM Table ORDER BY ID DESC");
$FindLastRow = mysqli_query($Database,"SELECT * FROM Table Where ID = /* $LastRowID - 3 */ ORDER BY ID DESC"); 

当这段代码运行时,它只选择$ LastRowID - 3行,但我需要在$ LastRowID - 3之后选择所有行;

实现这个目标的方法是什么?

2 个答案:

答案 0 :(得分:1)

这是一种方式......

  SELECT * FROM ints;
  +---+
  | i |
  +---+
  | 0 |
  | 1 |
  | 2 |
  | 3 |
  | 4 |
  | 5 |
  | 6 |
  | 7 |
  | 8 |
  | 9 |
  +---+

  SELECT * FROM ints ORDER BY i DESC LIMIT 3,100000;
  +---+
  | i |
  +---+
  | 6 |
  | 5 |
  | 4 |
  | 3 |
  | 2 |
  | 1 |
  | 0 |
  +---+

答案 1 :(得分:0)

SELECT x.* FROM
( SELECT * FROM Table ORDER BY Id DESC LIMIT 3) AS x
ORDER BY x.Id LIMIT 1

这会让你获得第三个最高ID的行。