哈哈这里我就不绕弯子了直接送上无上干货哈。
解释下,你可以使用union all来实现一条语句取3行数据,但是前提是3个查询的字段要相同(也就是select出来的字段要是一样的).
加入我们这里要查询的文章当前id是10那么语句如下:
(select id from table where id < 10 order by id asc limit 1) union all (select id from table where id = 10) union all (select id from table where id > 10 order by id desc limit 1);
这个查询出来的结果第一行就是上一篇文章,第二行是当前文章,第三行是下一篇文章。是不是很简单赶快试试吧。
除特别注明外,本站所有文章均为博文家原创,转载请注明出处来自https://www.32e.top/databases/mysql/article-15.html
暂无评论