2011-1118
下面是总结一下几种数据库要查询前n条记录的方法:

1. ORACLE
SELECT * FROM TABLE1 WHERE ROWNUM<=N
HQL: from table1 t order by t.createTime desc where rownum<=n

2. INFORMIX
SELECT FIRST N * FROM TABLE1

3. DB2
SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<=N
或者
SELECT COLUMN FROM TABLE FETCH FIRST N ROWS O 阅读全文>>
标签: 数据库 前N条记录 阅读:9824
2011-1118
id是指当前数据news_id参数


方法一:


string preSql = "select top 1 * from news where news_id < " + id + " order by news_id DESC"

string nextSql = "select top 1 * from news where news_id > " + id + " order by news_id ASC"


方法二:


string preSql = "select * from [news] where news_id = (select MAX(news_id) from [news]  阅读全文>>
标签: SQL 阅读:9887