MySQL实现根据当前ID读取上一条和下一条记录
当前ID为5,读取上一条记录:
SELECT * FROM A WHERE ID < 5 ORDER BY ID DESC LIMIT 0,1; ps: select * from table1 where id<$id order by id desc limit 1
当前ID为5,读取下一条记录:
SELECT * FROM B WHERE ID > 5 ORDER BY ID LIMIT 0,1; ps: select * from table1 where id>$id order by id asc limit 1
查询前n行记录 select * from table1 limit 0,n; 或 select * from table1 limit n;
查询第一行记录: select * from table limit 1
查询第n行到第m行记录: select * from table1 limit n-1,m-n;
SELECT * FROM table LIMIT 5,10;返回第6行到第15行的记录
select * from employee limit 3,1; // 返回第4行
相关推荐
苏康申 2020-11-13
vitasfly 2020-11-12
专注前端开发 2020-10-21
oraclemch 2020-11-06
liuyang000 2020-09-25
FellowYourHeart 2020-10-05
赵继业 2020-08-17
whyname 2020-08-16
Seandba 2020-08-16
dbasunny 2020-08-16
拼命工作好好玩 2020-08-15
langyue 2020-08-15
Accpcjg 2020-08-02
tydldd 2020-07-30
好记忆也需烂 2020-07-28
jianghero 2020-07-28