SQL在不同数据库中查询前几条记录的用法分类
1. orACLE
Select * FROM TABLE1 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 ONLY
4. SQL SERVER
Select TOP N * FROM TABLE1
5. SYBASE
SET ROWCOUNT N
GO
Select * FROM TABLE1
6. MYSQL
Select * FROM TABLE1 LIMIT N
7. FOXPRO
Select * TOP N FROM TABLE orDER BY COLUMN
8.postgres查询前几条记录SQL
Select * FROM TABLE LIMIT n
=================================================================================================
如在ms sqlserver 用此语句:
select top 2 * from test01 就会只显示前2条记录,
MYSQL/PostgreSQL
select * from your_table where .... limit 2;
//使用limit就可以了.
Oracle的语句:
select * from (select rownum r ,* from test) tt
where tt.r > 50 and tt.r <= 100; (最好用PLSQL游标来解决)
DB2中:
select * from payment fetch first 5 row only --查前5条记录