MySQL Formatting Guide

Learn MySQL-specific formatting tips and best practices

MySQL-Specific Syntax Support

MySQL has many unique syntaxes and functions, our formatter correctly recognizes and handles:

  • IFNULL(), COALESCE(), NULLIF() and other null handling functions
  • GROUP_CONCAT() aggregate function
  • LIMIT clause
  • ON DUPLICATE KEY UPDATE syntax
  • Stored procedures and function definitions

Formatting Example

Before formatting:

SELECT u.id,u.name,COUNT(o.id) as order_count FROM users u LEFT JOIN orders o ON u.id=o.user_id WHERE u.status='active' GROUP BY u.id,u.name HAVING COUNT(o.id)>0 ORDER BY order_count DESC LIMIT 10;

After formatting:

SELECT
  u.id,
  u.name,
  COUNT(o.id) AS order_count
FROM users u
  LEFT JOIN orders o ON u.id = o.user_id
WHERE u.status = 'active'
GROUP BY
  u.id,
  u.name
HAVING COUNT(o.id) > 0
ORDER BY order_count DESC
LIMIT 10;
MySQL Formatting Guide - SQL Formatter | SQL Formatter