how to find first and last record from mysql table

前端 未结 5 1860
失恋的感觉
失恋的感觉 2020-12-11 00:59

I have one table I want to find first and last record that satisfy criteria of particular month.

5条回答
  •  失恋的感觉
    2020-12-11 01:07

    First and last make sense only when you have the output of the query sorted on a field(s).

    To get the first record:

    select col1 from tab1 order by col1 asc limit 1;
    

    To get the last record:

    select col1 from tab1 order by col1 desc  limit 1;
    

提交回复
热议问题