Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
meemo
Starting Member
9 Posts |
Posted - 2012-04-13 : 10:55:03
|
Hi,I have a table which record an entry each time a user logs in the system. So, for example, a user can log in 1 or more times and it makes 1 or more entries to a tableID | AccessDate--------------------------------1 | Apr 11 2012 4:18PM2 | Apr 11 2012 4:28PM1 | Apr 11 2012 4:38PM2 | Apr 11 2012 4:18PM3 | Apr 11 2012 4:38PM1 | Apr 12 2012 4:18PMI'm trying to figure out how to get a list of all employees, order by id, but only show the last date they logged in. So, for example, the query would return the below for the above recordsID | AccessDate--------------------------------1 | Apr 12 2012 4:18PM2 | Apr 11 2012 4:28PM3 | Apr 11 2012 4:38PMHelp? |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-04-13 : 11:29:02
|
This should work if AccessDate is a datetime data type.SELECT ID, MAX(AccessDate) AS LatestAccessDateFROM YourTableGROUP BY IDORDER BY ID; |
 |
|
meemo
Starting Member
9 Posts |
Posted - 2012-04-13 : 11:46:15
|
Thanks, it worked! |
 |
|
|
|
|