internalsGet Pro

Module 02 · Lesson 9 of 12Pro

Deduplication: keeping one row per entity

Level
Intermediate
Topic
SQL for data engineering
Reading time
17 min

When you finish this page you can

  1. Tell exact copies, which DISTINCT removes, from versions of the same entity, which need a key and a rule.
  2. Choose a key for each source (a natural key, an event id, or a hash of normalised fields) and a tie-breaker that makes the order unique.
  3. Keep the newest row per key with ROW_NUMBER and QUALIFY, and explain when arg_max or DISTINCT ON give the same answer.
  4. Write uniqueness checks that fail the night before a duplicate reaches a report.
  1. Design: a first analytics pipeline for an online store30 min
  2. Window functions: running totals and rankings17 min

The same rows gave two different answers

is an online store in India. Every night its data team copies the day’s orders and click events from the store’s PostgreSQL database into , and Daniel, who leads finance reporting, reads the numbers at 07:00.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan