A batch contains multiple updates per order. Which SQL pattern selects the latest timestamp per order before an upsert?

Published
  1. SELECT DISTINCT order_id, amount, updated_at only
  2. ORDER BY updated_at without per-key reduction
  3. ROW_NUMBER partitioned by order_id, ordered by updated_at descending, then keep row 1
  4. GROUP BY order_id and choose any amount without ordering

Comments — 0