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_id | product_name | category | price | rating |
|---|---|---|---|---|
| 1 | MacBook Pro | Electronics | 1999.99 | 4.8 |
| 2 | iPad Air | Electronics | 599.99 | 4.8 |
| 3 | AirPods Pro | Electronics | 249.99 | 4.7 |