SQL formatter - format and beautify SQL online
Paste a query or a schema and get it back formatted: keywords uppercased, one clause per line, joins and conditions indented so the structure is readable. It parses the SQL (it doesn't just re-indent text), so the output is real SQL that still runs.
Works for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery, Snowflake, DuckDB and Redshift. Formatted on the server, discarded after the response.
Example
select o.id,c.name,sum(i.qty*i.unit_price) as total from orders o join customers c on c.id=o.customer_id join order_items i on i.order_id=o.id where o.created_at>=date '2024-01-01' and c.active group by o.id,c.name having sum(i.qty*i.unit_price)>100 order by total desc limit 20;
SELECT
o.id,
c.name,
SUM(i.qty * i.unit_price) AS total
FROM orders AS o
JOIN customers AS c
ON c.id = o.customer_id
JOIN order_items AS i
ON i.order_id = o.id
WHERE
o.created_at >= CAST('2024-01-01' AS DATE) AND c.active
GROUP BY
o.id,
c.name
HAVING
SUM(i.qty * i.unit_price) > 100
ORDER BY
total DESC
LIMIT 20;