A web-based tool for comparing SQL queries by their semantic meaning, not just syntax. It normalizes queries by resolving aliases, sorting conditions, and formatting output so you can easily identify if two queries are logically equivalent.
-
Semantic Comparison - Detects if two queries are logically equivalent regardless of:
- Different table aliases (
ovsorders) - Different column order in SELECT
- Different WHERE condition order
- Different JOIN order
- Different table aliases (
-
SQL Normalization - Automatically:
- Resolves and removes table aliases
- Sorts SELECT columns alphabetically
- Sorts WHERE conditions consistently
- Sorts JOIN clauses by type and table name
- Preserves ORDER BY (affects results)
-
Syntax Highlighting - Uses Prism.js for colorful SQL display
-
Diff View - When queries differ, highlights the differences
-
Modern UI
- Light/Dark theme toggle
- Font size zoom (10px - 20px)
- Minimalist, focused layout
- Keyboard shortcut:
⌘/Ctrl + Enter
-
Multi-Dialect Support
- MySQL
- PostgreSQL
- MariaDB
- SQL Server (T-SQL)
- Node.js 18+
- npm or yarn
# Clone the repository
git clone https://github.com/YOUR_USERNAME/sql-diff.git
cd sql-diff
# Install dependencies
npm install
# Start development server
npm run devOpen http://localhost:5173 in your browser.
npm run build
npm run preview- Paste your first SQL query in the left editor
- Paste your second SQL query in the right editor
- Click Compare or press
⌘/Ctrl + Enter - See the result: Equivalent ✓ or Different ✗
Query 1 (with aliases)
SELECT o.id, o.amount AS order_amount, c.name
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE o.status = 'active' AND c.country = 'US'Query 2 (without aliases, different order)
SELECT orders.id, customers.name, orders.amount AS order_amount
FROM orders
JOIN customers ON orders.customer_id = customers.id
WHERE customers.country = 'US' AND orders.status = 'active'Result: ✓ Semantically Equivalent
- Frontend: React 19
- Build Tool: Vite
- SQL Parsing: node-sql-parser
- Syntax Highlighting: Prism.js
- Styling: Vanilla CSS with CSS Variables
sql-diff/
├── src/
│ ├── components/
│ │ └── SqlEditor.jsx # Highlighted SQL editor
│ ├── utils/
│ │ ├── sqlNormalizer.js # Main orchestration
│ │ ├── aliasResolver.js # Alias detection & resolution
│ │ ├── elementSorter.js # Sorting algorithms
│ │ └── sqlPrettifier.js # Multi-line formatting
│ ├── App.jsx # Main application
│ ├── index.css # Styling
│ └── main.jsx # Entry point
├── index.html
├── package.json
└── vite.config.js
- Complex subqueries may not normalize perfectly
- Window functions sorting not fully supported
- CTEs (WITH clauses) have limited support
- Parser errors don't show exact line numbers
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- node-sql-parser - SQL parsing
- Prism.js - Syntax highlighting
