• SELECT * FROM [AD_in_Out LOG] as tLog

    INNER JOIN

    (SELECT USERID, MAX(CHECKTIME) as LastTime

    GROUP BY [userid]) as tREs

    ON tLog.Userid = tRes.Userid

    AND tLog.CHECKTIME = tREs.LastTime