![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
#4
| |||
| |||
|
#5
| |||
| |||
|
|
I have a table that includes a primary key, a timestamp, a username, and an |
#6
| |||
| |||
|
|
I have a table that includes a primary key, a timestamp, a username, and an BTW Timestamp is a reserved word. Don't use it for a column name unless the column name is in fact a TIMESTAMP (ROWVERSION) data type. I guess in this case that it isn't Timestamp data (which has nothing to do with date and time data) since you actually want to return the timestamp result. -- David Portas SQL Server MVP -- |
#7
| |||
| |||
|
|
Possibly this is what you want: SELECT L.lastlog, A.remote_computer FROM MemberAccess AS A JOIN (SELECT MAX(A.[timestamp]) AS lastlog, A.memberid FROM MemberAccess AS A JOIN Members AS M ON A.memberid = M.id WHERE M.username = @username GROUP BY A.memberid) AS L ON A.[timestamp] = L.lastlog AND A.memberid = L.memberid Or, if you prefer to use TOP: SELECT TOP 1 A.[timestamp] AS lastlog, A.remote_computer FROM MemberAccess AS A JOIN Members AS M ON A.memberid = M.id WHERE M.username = @username ORDER BY lastlog, A.remote_computer DESC -- David Portas SQL Server MVP -- |
![]() |
| Thread Tools | |
| Display Modes | |
| |