问题:
sql如何查询表的第一条记录和最后一条记录
方法一:使用top
select TOP 1 * from apple;
select TOP 1 * from apple order by id desc;
(备注:top是Access的语法,MySQL不支持)
方法二:使用LIMIT
第一条记录
mysql> select * from apple LIMIT 1;
默认升序,等价于
mysql> select * from apple order by id asc LIMIT 1;
最后一条记录
mysql> select * from apple order by id desc LIMIT 1;
版权声明:本文为lanyang123456原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。