mysql根据年查询,mysql如何指定查询一张表的最后5行记录和最前5行记录

更新时间:02-03 教程 由 暮夏 分享
mysql根据年查询,mysql如何指定查询一张表的最后5行记录和最前5行记录?

select * from student limit 5;

select * from student limit 0,5;

select * from student order by id asc limit 5;

前五条记录的查询语句。

查询后5条,注意结果为倒序排序,要使用desc

select * from student order by id desc limit 5

select * from student limit m,n;

返回m+1到m+n行记录,m代表开始的下标,n代表查找的结果数,将返回n行结果

select * from student limit 2,8; 返回3到10行记录

声明:关于《mysql根据年查询,mysql如何指定查询一张表的最后5行记录和最前5行记录》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_2209299.html