SQL BETWEEN Is Inclusive: Safer Date Range Queries
By Sharon Ben-Moshe · Aug 21, 2026
SQL BETWEEN includes both endpoints. Learn the timestamp boundary trap and use half-open date ranges that stay correct across databases.
Read postsqlfmt▍
Category
SQL formatting best practices, style guides, and conventions for readable queries.
19 posts
By Sharon Ben-Moshe · Aug 21, 2026
SQL BETWEEN includes both endpoints. Learn the timestamp boundary trap and use half-open date ranges that stay correct across databases.
Read postBy Sharon Ben-Moshe · Aug 21, 2026
DELETE removes selected rows, TRUNCATE empties a table, and DROP removes the table itself. Learn the crucial differences before running destructive SQL.
Read postBy Sharon Ben-Moshe · Aug 21, 2026
Use SQL transactions to make related changes together. Learn COMMIT, ROLLBACK, SAVEPOINT, autocommit, and portable safety checks.
Read postBy Sharon Ben-Moshe · Aug 21, 2026
A SQL CROSS JOIN returns every row combination from two inputs. Learn valid use cases, row-count math, safe formatting, and common mistakes.
Read postBy Sharon Ben-Moshe · Aug 21, 2026
DISTINCT removes duplicate result rows; GROUP BY creates groups for aggregation. Learn the practical difference, examples, and common query mistakes.
Read postBy Sharon Ben-Moshe · Aug 21, 2026
Use CASE inside SUM and COUNT to calculate several conditional metrics in one grouped SQL query. Learn the pattern, NULL behavior, and pitfalls.
Read postBy Sharon Ben-Moshe · Aug 8, 2026
A CREATE TABLE statement is the schema every future query has to live with — formatted well, it doubles as documentation. Here's a consistent, readable way to lay out columns, constraints, and keys.
Read postBy Sharon Ben-Moshe · Aug 8, 2026
A subquery buried inline in a WHERE clause or FROM list is unreadable the moment it grows past one line. Here's how to indent, align, and alias nested SELECTs so the outer query's structure stays visible.
Read postBy Sharon Ben-Moshe · Jul 13, 2026
Multi-row INSERT alignment, UPDATE SET clause style, DELETE WHERE formatting, and ON CONFLICT/MERGE upsert syntax across five SQL dialects, with examples.
Read postBy Sharon Ben-Moshe · Jul 13, 2026
Formatting SQL stored procedures means aligning parameters, indenting BEGIN/END blocks, and handling PL/pgSQL, T-SQL, and MySQL control flow correctly.
Read postBy Sharon Ben-Moshe · Jul 13, 2026
UNION and UNION ALL combine query results, but mismatched columns fail silently, not loudly. Here's how to align, parenthesize, and order them for readable SQL.
Read postBy Sharon Ben-Moshe · Jun 25, 2026
CTE vs subquery comes down to readability, reuse, and recursion. Here's when each one wins, plus the PostgreSQL optimization-fence gotcha you should know.
Read postBy Sharon Ben-Moshe · Jun 25, 2026
Window functions cram PARTITION BY, ORDER BY, and frames into one OVER clause. Here's how to format SQL window functions so the logic reads at a glance.
Read postBy Sharon Ben-Moshe · Jun 21, 2026
SQL CTEs turn into a wall of text fast. Here's how to format WITH clauses, multi-CTE chains, and recursive CTEs so the structure reads at a glance.
Read postBy Sharon Ben-Moshe · Jun 15, 2026
Multi-join queries turn into walls of text fast. Here's how to format JOINs, ON conditions, and join chains so the query structure reads at a glance.
Read postBy Sharon Ben-Moshe · Jun 15, 2026
SQL CASE statements get messy fast. Here's how to format simple, multi-branch, and nested CASE WHEN expressions to stay readable as logic grows.
Read postBy Sharon Ben-Moshe · Jun 14, 2026
Eight SQL formatting best practices — keyword casing, comma style, explicit JOINs, CTE usage, and keyword typo checking — with before-and-after examples.
Read postBy Sharon Ben-Moshe · Jun 14, 2026
Leading comma style in SQL places commas before each column, not after. Here's the case for and against it, and how to enforce it consistently.
Read postBy Sharon Ben-Moshe · Jun 14, 2026
Should SQL keywords be uppercase or lowercase? We compare major style guides, tool defaults, and team conventions to give you a clear, defensible answer.
Read post