This website uses cookies to ensure you get the best experience.
Learn more.
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
- Use SELECT DISTINCT on every column and assume it keeps only the latest version of each order.
- Use ROW_NUMBER partitioned by updated_at and omit all ordering columns.
- Use ROW_NUMBER partitioned by order_id and ordered by updated_at DESC, source_sequence DESC; retain row number 1.
- Order all rows globally by updated_at and retain only one row for the entire table.
Comments — 0
Sign in to comment