How to compare two SQL queries and spot the logic change
By TechCompare · Updated · How we check
Put each clause on its own line in both queries, then compare with Ignore case on. What's left is the change in filters, joins, sorting or limits.
The example
1 change: 7 lines removed, 7 added
| Original: paid-orders.sql | Changed: paid-orders.sql | ||||
|---|---|---|---|---|---|
| 1 | Removed | 1 | Added | select o.id, o.total, c.email | |
| 2 | Removed | 2 | Added | from orders o | |
| 3 | Removed | 3 | Added | join customers c on c.id = o.customer_id | |
| 4 | Removed | 4 | Added | where o.status in ('paid', 'refunded') | |
| 5 | Removed | | 5 | Added | and o.created_at >= '2026-01-01' |
| 6 | Removed | 6 | Added | order by o.created_at desc | |
| 7 | Removed | LIMIT 50; | 7 | Added | limit 100; |
Two versions of a query often differ in style more than in logic. One person writes SELECT in capitals, another writes select, and a formatter moves every clause onto its own line. None of that touches the results. A diff with Ignore case on hides it and leaves the edits that change what the query returns.
How this is calculated
In the example, the second query was rewritten with lowercase keywords and two real edits: the filter now includes refunded orders, and the limit changed. As typed, the tool reports 1 change: 7 lines removed, 7 added, since every keyword changed case. With Ignore case on, it reports 2 changes: 2 lines removed, 2 added. Those are the where line and the limit line.
SQL keywords don't depend on case, so for keyword style the switch is safe. Names and string values are another matter. MySQL on Linux can treat table names as case sensitive, and whether 'paid' and 'Paid' match the same rows depends on the database and its collation. Ignore case hides those changes too, so read the quoted values with the switch off before you sign off on a query.
Formatting is the other big source of noise. If one query is on a single line and the other puts each clause on its own line, nearly everything differs. Run both through the same formatter, or split them by hand at each keyword like FROM, JOIN, WHERE and ORDER BY. Ignore whitespace then takes care of different indentation.
Here's the patch the tool gives with case ignored:
--- a/paid-orders.sql
+++ b/paid-orders.sql
@@ -1,7 +1,7 @@
SELECT o.id, o.total, c.email
FROM orders o
JOIN customers c ON c.id = o.customer_id
-WHERE o.status = 'paid'
+where o.status in ('paid', 'refunded')
AND o.created_at >= '2026-01-01'
ORDER BY o.created_at DESC
-LIMIT 50;
+limit 100;Verdict
Compare queries with Ignore case on and the same formatting on both sides. Then read every line that's left, since a changed filter, join or limit changes the result set. Check quoted values with the switch off, because case can matter inside strings.
More Text Diff scenarios
Related guides
Frequently asked questions
Should I ignore case when comparing SQL?
How do I compare two queries that are formatted differently?
Related tools
JSON Formatter
Validate, format, and minify JSON. Browse it as a tree, run JSONPath queries, compare two documents, or validate against a JSON Schema.
Use toolCharacter Counter
Count characters, words, sentences, paragraphs, and lines. Check writing limits and count specific characters or phrases.
Use toolText Encoding Converter
Convert text to Base64, binary, hex, URL encoding and HTML entities, and back again.
Use tool