如何从mysql表中查找第一条记录和最后一条记录
问题描述:
我有一个表要查找满足特定月份条件的第一条记录和最后一条记录.
I have one table I want to find first and last record that satisfy criteria of particular month.
答
只有当您将查询的输出按字段排序时,第一个和最后一个才有意义.
First and last make sense only when you have the output of the query sorted on a field(s).
要获取第一条记录:
select col1 from tab1 order by col1 asc limit 1;
要获取最后一条记录:
select col1 from tab1 order by col1 desc limit 1;