Hard JOINsAggregation Premium

SQL interview question: Fuzzy Name Matching

Fuzzy Product Name Matching

Data cleaning team needs to find near-duplicate product names that might be the same item.

Find product pairs where names share common substrings (approximate similarity matching).

Return product_1, product_2, and similarity_score: shorter name length divided by longer, rounded to 2 decimals. Only pair products whose names contain 'Pro', each pair once with the lower product_id as product_1. Show the top 3 by score; on a tie, lower product ids first.

Skills: string functions and similarity concepts

Tables

products 20 rows
  • product_id integer PK
  • product_name text
  • category text
  • price real
  • rating real
product_idproduct_namecategorypricerating
1MacBook ProElectronics1999.994.8
2iPad AirElectronics599.994.8
3AirPods ProElectronics249.994.7

Keep going