MySQL: Get most recent record

后端 未结 7 1726
情歌与酒
情歌与酒 2020-11-28 20:42

In the table below, how do I get just the most recent record of id=1 based on the signin column and not all 3 records?

+----+--         


        
7条回答
  •  时光取名叫无心
    2020-11-28 21:08

    Building on @xQbert's answer's, you can avoid the subquery AND make it generic enough to filter by any ID

    SELECT id, signin, signout
    FROM dTable
    INNER JOIN(
      SELECT id, MAX(signin) AS signin
      FROM dTable
      GROUP BY id
    ) AS t1 USING(id, signin)
    

提交回复
热议问题