This is the error message from the select statementMsg 8120, Level 16, State 1, Line 1Column 'log.computername' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 145, Level 15, State 1, Line 1ORDER BY items must appear in the select list if SELECT DISTINCT is specified.1. distinct is applyed to whole row, not on computername only, so 'distinct computername, logontime' would return all distinct combinations of them.2. MAX(logontime) returns the maximum value of logontime for whole table and it is only one.If distinct computername returns 20 computernames and MAX(logontime) only one, the right rows can't be returnedselect computername, max(logontime) from log group by computernamewould return the right values, but I need a whole row (including userid and logofftime), and if I add userID and logofftime to select statemet, they also must be either in agregate function or in a group by clause. I dont know if it is an agregate function that returns the value retreived by finding the max value of another column (return logofftime and userID from the row where logontime has maximum value)