sql get most recent record

Solutions on MaxInterview for sql get most recent record by the best coders in the world

showing results for - "sql get most recent record"
Adriana
28 Feb 2019
1# Use the aggregate MAX(signin) grouped by id. This will list the most recent signin for each id.
2
3SELECT 
4 id, 
5 MAX(signin) AS most_recent_signin
6FROM tbl
7GROUP BY id
8
9# To get the whole single record, perform an INNER JOIN against a subquery which returns only the MAX(signin) per id.
10SELECT 
11  tbl.id,
12  signin,
13  signout
14FROM tbl
15  INNER JOIN (
16    SELECT id, MAX(signin) AS maxsign FROM tbl GROUP BY id
17  ) ms ON tbl.id = ms.id AND signin = maxsign
18WHERE tbl.id=1