SQL-Based Data Cleaning and Anomaly Detection Questions
Using SQL to profile, clean, and validate data: detecting duplicates, nulls, outliers, and referential-integrity breaks; writing production-safe diagnostic queries; and root-cause debugging of missing or incorrect data. Covers anomaly-detection queries and data cleaning for analytics. The hands-on SQL data-quality skill.
You suspect a customers table has near-duplicate rows that don't share an exact key: different casing, extra whitespace, typos, or slightly different formatting of the same underlying person or account. Write a fuzzy-matching query (for example using trigram similarity or edit-distance functions) that returns candidate duplicate pairs above a similarity threshold, and explain how you would tune that threshold to balance precision against recall.
A table has a JSON payload column that is expected to contain certain required keys (for example user_id and order_value). Write SQL that returns the rows where a required key is missing, or where a value that should be numeric can't be safely interpreted as one, along with example failing rows and counts.
Tell me about a time you investigated an unexpected anomaly in a production dashboard or metric. Using the STAR format, describe the situation, what you were responsible for, the specific steps you took to validate and investigate the issue (including any SQL checks you ran), and the outcome, including how you documented your assumptions and communicated with stakeholders.
Explain how SQL evaluates NULL in comparisons, boolean expressions, and aggregate functions. Why does col = NULL never match, and why do you need IS NULL / IS NOT NULL instead? Show how COALESCE and NULLIF are used to substitute or convert sentinel values, and how COUNT(*), COUNT(column), SUM, and AVG each treat NULLs differently. Also address the related design question: when should missing text be stored as NULL versus an empty string, and why does that choice matter for downstream validation checks?
Given a table where a handful of columns are considered critical for downstream analytics, write a query that flags every row where any of those critical columns is NULL, indicates which specific column(s) are NULL for that row, and reports the total count of problematic rows so the magnitude of the issue is clear at a glance.
Unlock Full Question Bank
Get access to all SQL-Based Data Cleaning and Anomaly Detection interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.