0
Essentially what you are looking for boils down to you wanting the username and location with the most recent time stamp. So, you want to ignore all the records whose last activity is not the greatest. Select sum(1) as testVar From session s Where location='chat.php' and datediff(minute, s.last...