PostgreSQL
 sql >> Database >  >> RDS >> PostgreSQL

Query SQL per ottenere la riga più recente per ogni istanza di una determinata chiave

Prova questo:

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