Back to Tools
SQL Formatting Guidelines
Indentation
- Use consistent indentation for clauses
- Indent sub-queries and CASE statements
- Align related columns and conditions
- Break long lines for readability
Keywords
- Use consistent case for SQL keywords
- Place major keywords on new lines
- Group related clauses together
- Use proper spacing around operators
Best Practices
- Use descriptive table and column aliases
- Comment complex queries
- Avoid SELECT * in production code
- Order clauses logically
SQL Reference
Query Clauses
- SELECT: Retrieve data from tables
- FROM: Specify source tables
- WHERE: Filter conditions
- GROUP BY: Group results
- HAVING: Filter groups
- ORDER BY: Sort results
Join Types
- INNER JOIN: Matching rows only
- LEFT JOIN: All from left table
- RIGHT JOIN: All from right table
- FULL JOIN: All from both tables
- CROSS JOIN: Cartesian product
Functions
- COUNT(): Count rows
- SUM(): Sum values
- AVG(): Average values
- MIN()/MAX(): Minimum/Maximum
- LENGTH(): String length
- UPPER()/LOWER(): Case conversion