1. 程式人生 > 資料庫 >常見資料庫SELECT結果只顯示前幾條記錄方法彙總

常見資料庫SELECT結果只顯示前幾條記錄方法彙總

常見資料庫SELECT結果只顯示前幾條記錄方法彙總

為了檢視資料表中的資料情況。經常會遇到想讓查詢結果只顯示N行,比如只顯示10行的情況。不同的資料庫有不同的關鍵字和SELECT實現語法。

1、SQL Server資料庫
select top 10  * from table_name;

2、DB2資料庫
select * from table_name fetch first 10 rows only;

3、Oracle資料庫
select * from table_name where rownum <=10;

4、MySQL資料庫
select * from table_name limit 10;

5、Informix 資料庫
select first 10 * from table_name;

6、Teradata資料倉庫
select * from table_name sample 10;

7.sqlite3資料庫

select  * from QGNe where (dg is null or dg=0) and lx=1 order by random() limit 6