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.sqlChanged: paid-orders.sql
1RemovedSELECT o.id, o.total, c.email1Addedselect o.id, o.total, c.email
2RemovedFROM orders o2Addedfrom orders o
3RemovedJOIN customers c ON c.id = o.customer_id3Addedjoin customers c on c.id = o.customer_id
4RemovedWHERE o.status = 'paid'4Addedwhere o.status in ('paid', 'refunded')
5Removed AND o.created_at >= '2026-01-01'5Added and o.created_at >= '2026-01-01'
6RemovedORDER BY o.created_at DESC6Addedorder by o.created_at desc
7RemovedLIMIT 50;7Addedlimit 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.

Changes in the example
1
7 lines removed, 7 added
Lines
7 and 7
Original and changed text
Category
Files and data
Text diff guides

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:

Unified diff 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

Frequently asked questions

Should I ignore case when comparing SQL?
Usually, yes. Keywords like SELECT and select mean the same thing. Turn it off when you need to check string values in quotes, or table names on a database that treats them as case sensitive.
How do I compare two queries that are formatted differently?
Format both the same way first, ideally with one clause per line. Then turn on Ignore whitespace so indentation doesn't count. A query on one long line gives a diff with a single changed line, which is hard to read even with word marks.