create table videos (id int);
insert into videos values (1), (2), (3), (4), (5);
-- Views table has 3 entries, video 2 watched 2 hours ago, video 4 watched 5 days ago, video 5 watched just now
create table views (video_id int, watched_at timestamp);
insert into views values
(2, current_timestamp - interval '2 hour'),
(4, current_timestamp - interval '5 day'),
(5, current_timestamp);
select id, last_watched_at
from videos
left join (
select video_id, max(watched_at) last_watched_at from views group by video_id
) last_views on id = video_id
order by last_watched_at asc nulls first