資料庫取前幾條記錄的語句

2021-05-22 15:38:50 字數 788 閱讀 9673

資料庫取前幾條記錄的語句

1. oracle

select * from table1 where rownum<=n

2. informix

select first n * from table1 where 1=1

3. db2

select * row_number() over(order by col1 desc) as rownum where rownum<=n

或者 select column from table where 1=1 fetch first n rows only

4.sqlserver

select top n * from table1 where 1=1

or set rowcount n select * from table1 where 1=1 set rowcount n1

5. sybase

set rowcount n select * from table1 where 1=1 set rowcount n1

6. mysql

select * from table1 where 1=1 order by radom() limit n

7. foxpro

select * top n from table order by column

8. access

select top n * from table1 where 1=1

常用資料庫 取前幾條資料 sql寫法

如在ms sqlserver 用此語句 select top 2 from test01 就會只顯示前2條記錄,mysql select from your table where limit 2 使用limit就可以了.oracle的語句 select from select rownum r f...

Oracle 中取前幾條記錄 分頁

oracle中用於類似mssql中top的關鍵字為rownumber,具體用法如下 select firmcode,balance from select rownum rn,t.firmcode,t.balance from firmbalance tab t order by balance d...

mysql分組取每組前幾條記錄

drop table if exists ho archives create table ho archives id mediumint 11 unsigned not null auto increment comment 自增id type smallint 5 unsigned not n...