怎样显示mysql数据库的最后一条记录,请给出sql语句

来源:百度知道 编辑:UC知道 时间:2024/05/22 03:42:51

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是伪列 只能用<
dl_会飞的青蛙的答案是错误的,他给出的是降序排列后的第一条,仅在排序过的时候是正确的。如果这个表是不排序的呢?他的答案就是错的

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

别人会不如自己会,这里有个教程,你看了就明白了

http://soft.yesky.com/lesson/486/2127486.shtml

select top 1 * from table order by field desc