您的位置:首页 > 博客中心 > 数据库 >

sql 查找最后一条记录

时间:2022-03-14 01:17

1.通过row

select * from table
where rownum<(select count(*)+1 from table)
minus
select * from table
where rownum<(select count(*) from table)

也可以简化为
select * from table
minus
select * from table
where rownum<(select count(*) from table)
效果是一样的

切记rownum是伪列 只能用<

顺便给你求第X行的通用SQL语句
select * from table where rownum<X+1
minus
select * from table where rownum<X

2.top

select top 1 * from person order by id desc

select top(1) * from table where id=(select max(id) from table)

3.max

select * from table a where a.date in (select max(b.date) from table b where b.id=a.id)

热门排行

今日推荐

热门手游