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
some_data AS ( select val from unnest(ARRAY['AAAABB', 'AAABBB']) as val)
SELECT *
FROM some_data;
update "notifications"
set "is_read" = 1,
"updated_at" = 2023 - 02 - 01 12:26:05
from ( select id from "notifications" where “client_id” = 126473 and "notifications"."client_id" is not null order by id for update) as t
where "notifications"."id" = t.id ;
SELECT id, created_at, contact_id, status
FROM contact_status
WHERE
contact_status.id in (select max(id) as id from contact_status group by contact_id)
contact_status.status = 'authorized'
ORDER BY contact_id, created_at DESC
SELECT id, created_at, contact_id, status
FROM contact_status
WHERE
contact_status.id in (select max(id) as id from contact_status where contact_id=121750 group by contact_id )
contact_status.status = 'authorized'
ORDER BY contact_id, created_at DESC