Mysql用select查询文章ID的上一篇和下一篇的方法!

/* 方式1: 获取给出id 的上一条,下一条 */

select * from t_article where id = (select id from t_article where id < 4 order by id desc limit 1);   

select * from t_article where id = (select id from t_article  where id > 4 order by id asc limit 1);

/* 方式2: 获取给出id 的上一条,下一条 */

select * from t_article  where id = (select max(id) from t_article where id < 4);   

select * from t_article  where id = (select min(id) from t_article where id > 4);

本文链接:https://www.dnwfb.com/1552.html,转载请注明出处。
0

评论0

没有账号? 注册  忘记密码?