I have a table Auditing logins, I'd like to just extract the latest login for each user, which the below sql accomplishes.
How would I format the sql query into a linq to sql query?
SELECT * FROM AuditTable adt1
inner join UserTable usr
on adt1.[UserName] = usr.[User_Id]
WHERE [TimeStamp] = ( SELECT MAX([TimeStamp])
FROM AuditTable adt2
WHERE adt1.UserName = adt2.UserName)
Another way of writing the query in sql being;
SELECT adt1.[UserName], usr.First_Name, max([TimeStamp]) as [TimeStamp]
FROM AuditTable adt1
INNER JOIN UserTable usr
on adt1.[UserName] = usr.[User_Id]
GROUP BY adt1.[UserName] ,usr.First_Name