medium10 pts · first answer countsdata-pipelinesdeduplicationsql
Keeping one row per order
Staging has duplicate rows per order_id, sometimes with the same updated_at. Which query keeps exactly one row per order, the latest, the same way on every run?
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (
PARTITION BY order_id
ORDER BY ???
) AS rn
FROM staging
) WHERE rn = 1Discussion 0
Join free to post in the discussion.