SQL不同数据库下的查询前n条记录

来源:互联网 时间:1970-01-01

SQL不同数据库下的查询前n条记录

1、MySQL

select * from table_name limit n

2、Oracle

select * from table_name where rownum <= n

3、SQLServer:

select top n * from table_name 

4、DB2

方法1:

 select ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM FROM TABLE_NAME WHERE ROWNUM<=n

方法2:

 select COLUMN FROM TABLE_NAME FETCH FIRST n ROWS ONLY 

4、Sybase

 sybase中查询前n条记录,比如现在n = 10

方法1:

SELECT TOP 10 * FROM table_name

方法2:  

 

set rowcount 10select * from table_name








相关阅读:
Top