$devtoolkit.sh/examples/sql/select-join

Format a SQL SELECT with JOIN

Multi-table JOIN queries quickly become hard to read when written on a single line or with inconsistent indentation. This example joins a users table with orders and applies filtering and sorting. The SQL formatter applies consistent keyword capitalization, indentation for JOIN conditions, and line breaks that match standard SQL style guides. Use formatted SQL in code reviews, documentation, and onboarding materials.

Example
SELECT u.id, u.name, u.email, COUNT(o.id) AS order_count, SUM(o.total) AS total_spent
FROM users u
INNER JOIN orders o ON u.id = o.user_id
INNER JOIN order_status os ON o.status_id = os.id
WHERE u.active = 1 AND os.name != 'cancelled'
GROUP BY u.id, u.name, u.email
ORDER BY total_spent DESC
LIMIT 20;
[ open in SQL Formatter → ]

FAQ

What is the difference between INNER JOIN and LEFT JOIN?
INNER JOIN returns only rows where the join condition matches in both tables. LEFT JOIN returns all rows from the left table plus matching rows from the right, with NULLs where there is no match.
Should SQL keywords be uppercase?
By convention, SQL keywords like SELECT, FROM, WHERE, and JOIN are written in uppercase while table and column names use lowercase or snake_case. The formatter enforces this convention.
What does aliasing do in SQL?
Aliases (AS or implicit with a space) give tables and columns shorter names within a query. Table aliases like u for users reduce repetition in JOIN conditions and SELECT lists.

Related Examples

/examples/sql/select-joinv1.0.0