Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Jim Lehmer

Rating No ratings yet

If you were handed two different but related sets of data, what tools would you use to find the matches? What if all you had was SQL SELECT access to a database? In this practical book, author Jim Lehmer provides best practices, techniques, and tricks to help you import, clean, match, score, and think about heterogeneous data using SQL. DBAs, programmers, business analysts, and data scientists will learn how to identify and remove duplicates, parse strings, extract data from XML and JSON, generate SQL using SQL, regularize data and prepare datasets, and apply data quality and ETL approaches for finding the similarities and differences between various expressions of the same data. Full of real-world techniques, the examples in the book contain working code. You'll learn how to: • Identity and remove duplicates in two different datasets using SQL • Regularize data and achieve data quality using SQL • Extract data from XML and JSON • Generate SQL using SQL to increase your productivity • Prepare datasets for import, merging, and better analysis using SQL • Report results using SQL • Apply data quality and ETL approaches to finding similarities and differences between various expressions of the same data

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Fuzzy Data Matching with SQL: Enhancing Data Quality and Query Performance ## 【One-Line Pitch】 A practical, code-first guide for anyone who needs to find matches between messy, heterogeneous datasets using nothing but SQL—covering everything from string parsing and data cleaning to building scoring systems for fuzzy matches. Ideal for DBAs, data analysts, and SQL developers who want to solve real-world data quality problems without leaving their database. ## 【Book Arc】 - **Opening (~0%–9%)**: Sets up the core problem—matching two related but differently formatted datasets—and explains why SQL is the right tool. Reviews basic SELECT syntax, introduces the book's simplified data model (customer tables, reference data), and warns about dialect differences across SQL servers. - **Early (~9%–28%)**: Dives into SQL fundamentals needed for data matching: CASE expressions for conditional logic, CTEs for readable queries, JOINs for combining tables, and the critical conversion functions (CAST, CONVERT, DATEADD, DATEDIFF, DATEPART) that handle type mismatches between datasets. - **Early–Middle (~28%–38%)**: Covers string manipulation functions in depth—LEFT, RIGHT, SUBSTRING, REPLACE, TRANSLATE, REVERSE, and PATINDEX—with practical examples like normalizing phone numbers and extracting name components. Introduces the recurring theme that data on either side of a match can be wrong, not just differently formatted. - **Middle (~38%–53%)**: Tackles the messy reality of name matching: suffixes, nicknames, "person-like entities" (companies vs. individuals), and the limitations of exact matching. Introduces the concept of building a "score" for fuzzy matches and acknowledges that some data problems (like "Mickey Mouse" entries from trade shows) are simply unsolvable. - **Late (~53%–100%)**: The excerpts do not cover the later chapters in detail, but based on the book's structure, this section presumably covers XML/JSON extraction, generating SQL with SQL, preparing datasets for import, and reporting results—the practical ETL and data quality workflows promised in the introduction. ## 【Key Takeaways】 - **SQL is a legitimate data matching tool** (Early): Despite the popularity of Python/R for data science, SQL SELECT access alone can handle most fuzzy matching scenarios—especially for "rectangular" row-and-column data already in relational databases. - **CASE expressions are the workhorse of conditional matching** (Early): Three syntax variations (single-line, multi-line with CASE after, multi-line with WHEN after) all work; choose based on readability. For simple if-then-else, IIF is terser. - **CAST and CONVERT solve type mismatch problems** (Early): Left-padding ZIP codes with `RIGHT('00000' + CAST(zip AS VARCHAR), 5)` is a classic example—explicit casting tells SQL to concatenate rather than add, and the WHERE clause optimization avoids unnecessary processing on already-correct data. - **String functions are the core toolkit for data cleaning** (Early–Middle): LEFT, RIGHT, SUBSTRING, REPLACE, and TRANSLATE handle most parsing needs. TRANSLATE is better for changing multiple characters at once; combining it with REPLACE produces shorter, more debuggable expressions. - **Guard against edge cases in string calculations** (Early): Dynamically computed lengths for LEFT/RIGHT can yield negative values (causing errors) or zero (returning empty strings). Always use IIF or CASE to check for patterns before calculating lengths. - **Name matching requires accepting imperfection** (Middle): Nicknames ("James" vs. "Jim"), suffixes, and even spouses with identical names (Donald and Donna) mean exact matching fails. Practical compromises include matching on first initial only or building a confidence score from multiple attributes. - **"Person-like entities" need heuristic detection** (Middle): When datasets mix companies and individuals, searching for "magic words" (like "& Sons" or "L.L.C.") in names works most of the time—ugly but effective. Normalizing by removing punctuation and spaces helps standardize entity names. - **Data quality issues are expected, not exceptional** (Middle): Birth dates in the future, transposed characters, and outright lies in marketing-sourced data are common. The book's philosophy is to build scoring systems that tolerate fuzziness rather than demanding perfect matches. ## 【Reading Tips】 - **Skim Chapters 1–2 if you're comfortable with SQL basics** (~0%–28%): The SELECT review and function reference are thorough but standard. Focus on the CASE expression variations and the string function examples—these are the building blocks for everything later. - **Deep-read the string parsing sections** (~28%–38%): The phone number normalization and name extraction examples are the most transferable techniques. Pay special attention to the IIF-guarded SUBSTRING/RIGHT patterns that handle missing suffixes gracefully. - **Don't skip the "person-like entities" discussion** (~47%–53%): The magic-word approach to detecting companies feels hacky but is genuinely practical. The discussion of name matching limitations (nicknames, same-name spouses) sets up the scoring concept that's central to the book's approach. - **Watch for dialect differences**: The book uses SQL Server syntax (TOP, GETDATE, DATEADD) but notes DB2 alternatives. If you're on PostgreSQL or MySQL, mentally translate as you read—the patterns transfer, the syntax doesn't. - **Use the downloadable code**: The book references supplemental code at the O'Reilly site. Run the examples yourself, especially the variable-based demos that don't require full table setups—they're quick to test and modify. ## 【Coverage Limits】 This guide covers the book's opening through approximately the middle (~53%). The later chapters on XML/JSON extraction, SQL generation, dataset preparation, and reporting are not covered in the available excerpts—refer to the book's table of contents for those topics. ##
Page 11
easons, but these are the chief two: Identify new prospects Filter out existing customers from the list and send the new prospects down a low-cost, standardi...
View in text
Excerpt 2
xpressed all in a line: CASE City WHEN USPSCity THEN 'Match!' ELSE 'No Match!' END [Match?] You can read it like this: “In the CASE of the value in City, WHE...
View in text
Excerpt 3
with no formatting that often get converted into integers. The string “05436” gets interpreted as the number 5436 and so on: SELECT 0 [One Digit], 500 [Three...
View in text
Excerpt 4
if someone goes by “Junior” all their life, they may write down “Junior” in a first name box or on their name tag. There is not much you can do about this, f...
View in text
Excerpt 5
chapter understanding that when it comes to data matching, more attributes to match against do not necessarily lead to better results! If there is “junk data...
View in text
Excerpt 6
NCHAR(8205) + NCHAR(8232) + NCHAR(8233) + NCHAR(8239) + NCHAR(8287) + NCHAR(8288) + NCHAR(12288) + NCHAR(65279), 31 UNICODE spaces to translate to (note "N")...
View in text
Excerpt 7
s) - 1 ) PATINDEX ( RIGHT ( @FullAddress, LEN(@FullAddress) - PATINDEX('%, %', @FullAddress) ) ) ) [City], State is somewhat easy - it is the first two chara...
View in text
Excerpt 8
ne matching on first name, address, and postal code. On the other hand, the latter might be considered a strong enough match itself. These are going to end u...
View in text
Tags
AI categories
SQLDatabaseData
ISBN: 1098152271
Publisher: O'Reilly Media
Publish Year: 2023
Language: English
Pages: 285
File Format: PDF
File Size: 1.9 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…