Diffing two SQL queries as raw text almost never shows what actually changed: one version keyworded in lowercase, the other in upper; one wrapped at 80 characters, the other at 120 — none of that is a real change, but a text-level diff can't tell the difference between "reformatted" and "rewritten." This tool runs both queries through the exact same sql-formatter pass — same dialect, same casing, same indentation — before comparing them line by line, so a reformatting produces an *identical* pair, and the diff is empty. What is left after that is the change that matters.
The example below is loaded into the editor above: a query gains a WHERE filter and an ORDER BY / LIMIT for pagination. Both queries format to the same style, so the diff below isolates exactly those additions — not a single line of noise from the reformatting itself.
The example, before and after formatting
This is loaded into the Before/After editors above.
SELECT
u.id,
u.name,
COUNT(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
GROUP BY
u.id,
u.name;SELECT
u.id,
u.name,
COUNT(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.status = 'active'
GROUP BY
u.id,
u.name
ORDER BY
orders DESC
LIMIT
20;How it works
The diff is line-level, computed the same way `diff` computes one
This isn't a naive line-by-line comparison, which would make one inserted line in the middle look like every following line changed. It implements Myers' shortest-edit-script algorithm — the same algorithm behind the Unix diff utility and git diff — which finds the minimal set of line additions and removals that turns the Before query into the After one.
In the example, the new WHERE clause and the new ORDER BY / LIMIT clause are the only lines marked changed; every line that exists in both queries, including the ones after the insertion point, stays unmarked.
Formatting first is what makes the diff meaningful
Both queries are formatted with the dialect and options selected above before anything is compared. Paste the exact same query into both boxes, in whatever style you originally wrote it, and the diff will show nothing — which is the correct answer, and the quickest way to confirm that a change you made was purely cosmetic.
When a query fails to format
If a query doesn't parse under the selected dialect, this tool falls back the same way the SQL Formatter does: a reduced option set, then a generic SQL pass, before giving up and reporting an error. A diff still needs both sides to have gone through the same fallback path to be meaningful, so if one side hits the generic fallback and the other doesn't, minor formatting differences from that mismatch can appear as noise in the diff.
Known limitations
- The diff is line-based, not token-based: a single word changed in the middle of a long line (an alias renamed, a literal value changed) marks the whole line as removed and re-added, rather than highlighting just the changed word within it.
- Comparing across two different dialects is possible — the tool doesn't prevent it — but rarely useful, since the same query can format differently under different dialects' grammars for reasons that have nothing to do with an actual edit.
SQL Diff FAQ
Why does pasting the same query on both sides sometimes still show a diff?
It shouldn't, and doesn't, as long as both sides parse the same way under the selected dialect. If one side hits a different fallback level than the other — one needs the generic pass, the other doesn't — the two can end up formatted slightly differently even though the input was identical.
Can I compare queries written in different SQL dialects?
The tool lets you, but a diff across two different grammars usually reflects dialect differences, not a real edit — it's built for comparing two versions of the same query in the same dialect.
Does it diff whole statements or individual lines?
Lines, after formatting — the same unit git diff uses for code. A change inside a single line (like a renamed column) marks that whole line as changed, not just the changed portion of it.
Are my queries uploaded anywhere?
No. Formatting and diffing both run in your browser, which matters here since comparing two versions of a query often means comparing two versions with real table and column names in them.