在新闻、文章信息类的网站程序中经常需要在一篇文章最下端加上“上一篇”和“下一篇”记录的链接信息,在SQLServer中可以用以下sql语句来实现:
string preSql = "select * from [news] where news_id = (select MAX(news_id) from [news] where news_id<" + id + ")"; string nextSql = "select * from [news] where news_id = (select MIN(news_id) from [news] where news_id>" + id + ")";