資料庫分頁的SQL語句

2021-04-28 14:30:10 字數 432 閱讀 4656

請注意:

如果取第乙個15條記錄,sql語句不能這樣寫:

select top 15  *  from yourtable where id not in(select top 0 id from yourtable order by id desc)  order by id desc

這樣寫會報錯。直接寫成:

select top 15  *  from yourtable   order by id desc

如果要加限制條件,可以這樣寫:

select top 15  *  from yourtable where id not in(select top 15 id from yourtable where  name='wallimn' order by id desc) and name='wallimn'  order by id desc

常見資料庫分頁SQL語句

我們在編寫mis系統和web應用程式等系統時,都涉及到與資料庫的互動,如果資料庫中資料量很大的話,一次檢索所有的記錄,會占用系統很大的資源,因此我們常常採用,需要多少資料就只從資料庫中取多少條記錄,即採用分頁語句。根據自己使用過的內容,把常見資料庫sql server,oracle和my sql的分...

常見資料庫分頁SQL語句

sql server 從資料庫表中的第m條記錄開始取n條記錄,利用top關鍵字 注意假如select語句中既有top,又有order by,則是從排序好的結果集中選擇 select from select top n from select top m n 1 from 表名稱 order by 主...

常見資料庫分頁SQL語句

sql server 從資料庫表中的第m條記錄開始取n條記錄,利用top關鍵字 注意如果select語句中既有top,又有order by,則是從排序好的結果集中選擇 select from select top n from select top m n 1 from 表名稱 order by 主...