A staging table contains several versions per order_id. Each version has updated_at and a unique increasing source_sequence. The target needs exactly the newest row per order, including deterministic handling of timestamp ties. Which SQL approach is appropriate?

Published
  1. Use SELECT DISTINCT on every column and assume it keeps only the latest version of each order.
  2. Use ROW_NUMBER partitioned by updated_at and omit all ordering columns.
  3. Use ROW_NUMBER partitioned by order_id and ordered by updated_at DESC, source_sequence DESC; retain row number 1.
  4. Order all rows globally by updated_at and retain only one row for the entire table.

Comments — 0