读书人

SQL查询下一篇上一篇合成一个查询语句

发布时间: 2012-09-14 11:53:44 作者: rapoo

SQL查询上一篇下一篇合成一个查询语句
当前ID为234,下面两个语句可以选出上一篇,下一篇,我想要把他合成一个查询语句可以吗。应该怎么做
select top 1 * from emailRC where id>234 order by id
select top 1 * from emailRC where id<234 order by id desc

查询出来的结果如
preID nextID
231 248


[解决办法]

SQL code
select min(id) from emailRC where id>234 Union select max(id) from emailRC where id<234 

读书人网 >SQL Server

热点推荐