oracle取前n条数据,各种取数据库取前N条记录的Sql语句

本文详细介绍了在不同数据库中如何获取前N条数据的SQL语句,包括Access、DB2、MySQL、SQL Server和Oracle。例如在Oracle中,可以使用rownum配合子查询来实现,而在SQL Server中,可以使用top关键字。同时,文章还解释了MySQL中limit子句的使用方法。
摘要由CSDN通过智能技术生成

access:

select top (10) * from table1

db2:

select 列名 from table1 where 1=1 fetch first 10 rows only

mysql:

select * from table1 limit 10 或 select * from table1 limit 0,10

sql server:

读取前10条:select top (10) * from table1 where 1=1

在sqlserver里面,若每页显示perpage条记录,按照id的排序,取第pageno页的记录:

select top perpage*pageno   * from table where id not in(select top (pageno-1)*perpage id from table1)

oracle取前10条:

select * from table1 where rownum<=10

oracle取第11-20条:

select * from (select *,rownum num from table1 where rownum<=20) where num>=10;

oracle按id排序后取11-20条

select * from (select *,rownum num from (select * from table1 tt order by id desc) where rownum<=20) where num>=10;

关于mysql 的limit 子句的使用方法:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值