how to find first and last record from mysql table

前端 未结 5 1861
失恋的感觉
失恋的感觉 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:28

    SELECT 
    (SELECT column FROM table WHERE [condition] ORDER BY column LIMIT 1) as 'first',
    (SELECT column FROM table WHERE [condition] ORDER BY column DESC LIMIT 1) as 'last'
    

    This worked for me when I needed to select first and the last date in the event series.

提交回复
热议问题