← Back to blog tutorial

Data Cleaning in SQL: A Practical Guide With Examples

Hendri · 4 min read · Sep 30, 2026

data-cleaning sql duckdb tutorial
Data Cleaning in SQL: A Practical Guide With Examples

TLDR: SQL is a great way to clean data when the file is already in a database or when you want the cleaning logic to be explicit and auditable. You can trim, fix casing, standardize dates, clean numbers, handle nulls, and deduplicate, all with queries. For large CSVs that live as files, the same SQL runs in the browser with DuckDB, no upload needed.

Searches for "data cleaning in sql" and "cleaning data in sql" are steady, and the broader "sql for data analysis" cluster is one of the highest-volume groups in our keyword set. The intent is clear: analysts who already know some SQL wonder whether they should write cleaning queries, or just use a visual tool.

This guide shows both, with the same messy healthcare claims file as an example, so you can see the SQL side by side with the no-code alternative.


When SQL is the right tool

SQL makes sense when your data already lives in a database, or when you want the cleaning logic to be readable, versionable, and auditable. Every transform is a query you can review, share, and run again.

You do not need a database server to use SQL on a CSV. Tools built on DuckDB, like Mungr, let you run SQL directly on a file in the browser, with the file never leaving your machine.

The same file, in SQL

Take a 50,000-row healthcare claims export with whitespace in names, mixed department casing, dates in eight formats, charge amounts like "$ 2,100.00" and "2100.00 USD" in one column, empty cells, and about 1% exact duplicate rows.

Here is what the cleaning looks like in DuckDB SQL, which also runs inside Mungr's Custom SQL step.

Trim whitespace

UPDATE claims
SET FullName = TRIM(FullName),
    Department = TRIM(Department),
    DiagnosisCode = TRIM(DiagnosisCode);

Fix casing

-- Title case for names and departments
UPDATE claims SET Department = INITCAP(Department);

Standardize dates to YYYY-MM-DD

UPDATE claims
SET VisitDate = STRPTIME(VisitDate, '%Y-%m-%d');
-- DuckDB auto-detects most formats; specify the source pattern when ambiguous

Clean numbers

UPDATE claims
SET ChargeAmount = CAST(REGEXP_REPLACE(ChargeAmount, '[\$,\sUSD]+', '') AS DOUBLE);

Handle nulls per column

UPDATE claims SET Status = COALESCE(Status, 'Pending');
-- Leave Phone and Email as NULL when genuinely unknown

Deduplicate on exact row match

CREATE TABLE claims_clean AS
SELECT DISTINCT * FROM claims;

Save that as a recipe. Next month's export with the same columns takes the same queries, every time.

When a visual tool is faster

The SQL above works, but it is still code you have to write, test, and maintain. If a column name changes next month, the query breaks. If a teammate needs to run it, they need the same SQL environment.

In a no-code tool like Mungr, the same steps are visual: trim, change case, standardize dates, regex replace, fill nulls, deduplicate, then save as a recipe. No environment to set up, no query to debug, and the recipe is shareable as JSON and exportable as SQL for when you do need it in a pipeline.

Many teams use both: a visual recipe for the monthly export, and SQL for the deeper analysis after.

Frequently asked questions

Do I need SQL to clean data?

No. SQL is one way. No-code tools like Mungr, OpenRefine, and Excel Power Query handle trimming, deduplication, date fixing, and reshaping through a visual interface. SQL is useful when you want the logic to be explicit and auditable.

Is SQL good for cleaning large CSV files?

Yes, if the engine is right. Spreadsheet SQL is slow on large files. A columnar engine like DuckDB handles millions of rows, and in a browser-based tool it does so without uploading the file.

Can I run SQL on a CSV without a database?

Yes. DuckDB can query a CSV directly, and tools like Mungr compile DuckDB to WebAssembly so the query runs in your browser, with the file never leaving your machine.

What SQL should I learn first for data cleaning?

Start with TRIM, UPPER and INITCAP, STRPTIME for dates, REGEXP_REPLACE for stripping symbols, COALESCE for nulls, and SELECT DISTINCT for deduplication. Those cover most messy files.


Bottom line

SQL gives you the most auditable cleaning logic, and it is the right choice when your data already lives in a database or you want the transforms to be explicit. No-code tools give you the same steps without writing queries, with the added benefit that some, like Mungr, keep everything local for sensitive data.

Try Mungr free — SQL and no-code, no upload


Related: Data Cleaning in Python vs No-Code Tools: When to Use Which · How to Clean a Large CSV Without Writing Code or Uploading Your Data · What Is a Data Cleaning Tool? A Plain-English Guide

Ready to try privacy-first data cleaning?

Get started for free