InterviewStack.io LogoInterviewStack.io

Data Cleaning and Quality Validation in SQL Questions

Handle NULL values, duplicates, and data type issues within queries. Implement data validation checks (row counts, value distributions, date ranges). Practice identifying and documenting data quality issues that impact analysis reliability.

EasyTechnical
81 practiced
You receive a table of user emails with inconsistent casing and leading/trailing whitespace. Given:
contacts(id INT, raw_email TEXT)
Write a SQL SELECT that returns cleaned_email (trimmed and lowercased) and flags rows where the cleaned_email does not match a standard email regex. Use PostgreSQL or standard SQL functions. Also describe whether storing cleaned_email in the warehouse is appropriate vs. cleaning at query-time.
HardSystem Design
79 practiced
Design an alerting and triage workflow for data quality incidents that is resilient and minimizes on-call noise. Provide a schema for a DQ_incidents table capturing (incident_id, check_name, severity, detected_at, status, assigned_to, sample_rows_link) and write a sample SQL that, given a failing check, selects a small representative sample of offending rows for immediate inspection (include columns to help debug: primary key, ingestion_batch_id, minimal context).
MediumTechnical
92 practiced
Explain how to implement row-level data lineage using only SQL constructs: capture source_file, source_row_id, ingestion_batch_id in staging, propagate these fields through transformations, and provide a sample SQL pattern that joins a transformed analytics row back to its originating source rows for root cause analysis. Use example table names: staging.raw_events and analytics.daily_events.
MediumTechnical
81 practiced
You discovered that numeric amounts are stored as text and include formatting like '$1,234.56' and '(1,234.56)' for negatives. Write PostgreSQL SQL to clean and cast amount_text into a numeric column 'amount', correctly handling commas, currency symbols, and negative values in parentheses. Show how you'd surface rows that still fail casting after cleaning.
MediumTechnical
76 practiced
Create a single SQL query that runs multiple data quality checks for an orders and products dataset and emits a standardized results table with columns: check_name, expected, observed, status. Checks should include: uniqueness of order_id in orders, product_id in products exists for all order items (referential integrity), and null rate for order_date. Use these schemas:
orders(order_id STRING, order_date DATE)
order_items(order_item_id STRING, order_id STRING, product_id STRING)
products(product_id STRING)
Return a single result set with the three checks.

Unlock Full Question Bank

Get access to hundreds of Data Cleaning and Quality Validation in SQL interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.