A customer staging table has multiple records per customer_id. Each has an updated_at timestamp and a unique ingestion_id. Keep the latest timestamp, breaking ties with the highest ingestion_id. Which approach is deterministic?

Published
  1. Use ROW_NUMBER() ordered only by customer_id
  2. Use ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY updated_at DESC, ingestion_id DESC) and keep row 1
  3. Use SELECT DISTINCT on every column
  4. Group by customer_id and take MAX(updated_at) with an arbitrary address

Comments — 0