SQL UNION vs UNION ALL: Duplicate Rules and Performance
By Sharon Ben-Moshe · August 16, 2026 · 1 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
UNION removes duplicate rows; UNION ALL keeps every row. Learn compatibility rules, ordering scope, and how to choose the correct set operator.
Quick answer
UNION combines compatible result sets and removes duplicate output rows by default. UNION ALL combines the same kind of result sets but retains every row, including duplicates. Use UNION only when deduplication is part of the requirement; otherwise UNION ALL preserves the full input.
Keep reading
BigQuery QUALIFY Clause: Filter Window Functions Directly
By Sharon Ben-Moshe · Aug 16, 2026
Use BigQuery QUALIFY to filter window-function results without an outer subquery. Learn evaluation order, top-N-per-group patterns, and portability.
Read postSQL Window Functions vs GROUP BY: Keep Detail Rows
By Sharon Ben-Moshe · Aug 16, 2026
GROUP BY collapses rows; window functions retain detail and add calculations beside it. See when each approach fits, with clear SQL examples.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.