数据库查询前N条记录sql语句介绍

时间:2023-02-08 23:24:05

1.MSSQL

a)查询前n条记录:

     select top n * from  table_name;

b)查询第n条到第m条记录:

     select top n * from (select top m * from table_name order by column_name) a order by column_name desc

 

2. MySQL

a) 查询前n条记录

    select * from table_name limit 0,n

b) 查询第n条到第m条

select * from table_name limit n,m

 

 

3.oracle

a)查询前n条记录

   select * from table_name where rownum<n

b)查询第m条到第n条记录:

select * from (select a.*,a.rownum rn from (select * from table_name)  a  where  a.rownum<m) where rn>n