如何选择最低记录但不是最低记录

时间:2015-01-25 23:31:33

标签: sql select

数据库中的记录:

1
5
6
7
8
10

$select_query = "SELECT * FROM  images_tbl where images_id = $NextID ORDER BY images_id DESC LIMIT 1";

因此,如果$ NextID为10,则下一个最低记录应为8而不是1

2 个答案:

答案 0 :(得分:1)

$select_query = "SELECT * FROM  images_tbl ORDER BY images_id ASC LIMIT 1,1";

答案 1 :(得分:1)

你不希望one = $ nextID,你希望下一个“down”。

$select_query = "SELECT Top 1 * FROM  images_tbl where images_id < $NextID ORDER BY images_id DESC