select
keys.*
from keys.*
join
(select max(issued_at) as issued_at, user_login from keys group by user_login) as last
on
last.user_login = keys.user_login and last.issued_at = keys.issued_at
select
"user_login",
(select key "user_login" from keys as last where keys.id = last.id order by issued_at desc limit 1) as key
from keys
group by "user_login"
SELECT
user_login,
LAST_VALUE(key) OVER(ORDER BY issued_at desc) as last_key
FROM
keys
group by "user_login";
SELECT
user_login,
ARRAY_AGG(key ORDER BY issued_at desc)[0]
FROM
keys
group by "user_login";
with d as (
select
*,
row_number() over (partition by user_login order by issued_at) rn
from tbl
) select * from d where rn = 1;