Last updated
Common SQL Formatting Use Cases
- Beautifying SQL from ORM-generated queries for debugging
- Formatting SQL from database logs for analysis
- Cleaning up SQL before committing to version control
- Making complex queries readable for code review
- Formatting migration scripts for team review
- Validating SQL syntax before running against production
All formatting happens entirely in your browser. Supports MySQL, PostgreSQL, SQL Server, Oracle, and SQLite dialects. Your queries are never transmitted to any server.
Examples
Example 1: Basic SELECT Query
Input (minified):
SELECT u.id,u.name,u.email,o.total FROM users u JOIN orders o ON u.id=o.user_id WHERE u.active=1 AND o.status='completed' ORDER BY o.total DESC LIMIT 10
Output (formatted):
SELECT
u.id,
u.name,
u.email,
o.total
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE
u.active = 1
AND o.status = 'completed'
ORDER BY o.total DESC
LIMIT 10
Example 2: Complex Multi-Table JOIN
Input:
select u.name,p.title,c.content,c.created_at from users u inner join posts p on u.id=p.author_id left join comments c on p.id=c.post_id where u.role='author' and p.published=true and c.approved=true order by c.created_at desc
Output:
SELECT
u.name,
p.title,
c.content,
c.created_at
FROM users u
INNER JOIN posts p ON u.id = p.author_id
LEFT JOIN comments c ON p.id = c.post_id
WHERE
u.role = 'author'
AND p.published = true
AND c.approved = true
ORDER BY c.created_at DESC
Example 3: Subquery Formatting
Input:
SELECT * FROM products WHERE category_id IN (SELECT id FROM categories WHERE parent_id = (SELECT id FROM categories WHERE name = 'Electronics'))
Output:
SELECT *
FROM products
WHERE
category_id IN (
SELECT id
FROM categories
WHERE
parent_id = (
SELECT id
FROM categories
WHERE name = 'Electronics'
)
)