Data Cleaning Exercises

Reference · SQL (DuckDB)

Look up values from another table in SQL (DuckDB)

Bring columns from a lookup table by key, keeping every row and never matching missing keys.

When to use it

Enriching rows with master data (customer region, account name).

How

LEFT JOIN on the key. NULL keys never match.

FROM orders o LEFT JOIN customers c ON o.customer_key = c.customer_key
  • Check that row counts are unchanged after the join.

Pitfalls

  • Fan-out from a non-unique lookup key.
  • Missing keys matching each other in pandas.
  • Inner joins that drop rows silently.

Lesson: Joins where missing keys never match

Practise it: Join orders to customers without matching blanks