Find the bugs: two most recent events per user

Return the two most recent events for users 1 and 2, showing the columns id, user_id, and event_type. The most recent event is the one with the highest created_at. If timestamps are tied, the event with the highest id wins. The query runs without errors but returns the wrong events. Find the lines that need to be fixed.

Find the errorsWindow functionsJuniorAnalystData Engineer
Input data · iv_events
iduser_idevent_typecreated_at
11login2026-01-31 23:59:00
21login2026-01-31 23:59:00
31view2026-02-01 00:00:00
42login2026-02-01 08:00:00
52view2026-02-01 08:05:00
62view2026-02-01 08:05:00
73login2026-02-02 10:00:00
8NULLview2026-02-03 11:00:00
91purchase2026-02-03 12:00:00
102logout2026-02-28 23:59:59
SELECT id, user_id, event_type
FROM (
  SELECT id, user_id, event_type,
         ROW_NUMBER() OVER (
           PARTITION BY user_id
           ORDER BY created_at ASC, id ASC
         ) AS rn
  FROM iv_events
  WHERE user_id IN (1, 2)
) t
WHERE rn <= 2
ORDER BY user_id, id