我有一张包含客户详细信息的表格
id,title,first_name,surname
当我使用
时SELECT * FROM customers ORDER BY surname,first_name,title;
如何在不读取整个表的情况下根据id获取上一行或下一行。
答案 0 :(得分:2)
下:
SELECT * FROM customers WHERE id > XYZ ORDER BY id ASC LIMIT 1
前面的:
SELECT * FROM customers WHERE id < XYZ ORDER BY id DESC LIMIT 1
其中XYZ是您的号码
答案 1 :(得分:0)
如果ID类型是整数且nextID = currentID + 1
。所以你可以把你的查询写成:
SELECT *
FROM customers
WHERE id = (currentID + 1)
ORDER BY surname,first_name,title;