I have trying to get the latest results using SQL. I searched the website and found this old post from 'stackoverflow', link:
SQL query to get most recent row for each instance of a given key
I copied the most accepted answer here.
Select u.[username]
,u.[ip]
,q.[time_stamp]
From [users] As u
Inner Join (
Select [username]
,max(time_stamp) as [time_stamp]
From [users]
Group By [username]) As [q]
On u.username = q.username
And u.time_stamp = q.time_stamp
The thing I do NOT understand is why can't we simply use below (ie: why do need the 'inner join' operation in this case)?
Select username, ip, max(time_stamp) as time_stamp
From users
Group By username