SQL Set Operations Visualizer
UNION vs UNION ALL, INTERSECT vs INTERSECT ALL, EXCEPT vs EXCEPT ALL: the difference is always about duplicates, and duplicates are hard to reason about in your head. This visualizer runs the set operation on real rows instead. Paste the two result sets as CSV, pick the operation, and see the exact rows that come back, how many rows each side had before and after deduplication, and the SQL for PostgreSQL, MySQL, SQL Server, Oracle or SQLite, with a note whenever a dialect lacks the operator. Everything runs in your browser; nothing is uploaded.
Do more than sql set operations visualizer — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Edit the left and right result sets as CSV. The first line is the header; leave a cell empty to represent NULL.
- Pick the set operation and your SQL dialect. Column count must match on both sides, exactly as in a real database.
- Read the result rows, the before/after row counts and the generated SQL, then copy the statement into your query editor.
Frequently asked questions
What is the difference between UNION and UNION ALL?
UNION ALL appends the rows of the second query to the rows of the first and returns everything, duplicates included. UNION does the same and then removes duplicate rows, comparing every column, which forces the database to sort or hash the combined result. With the sample data, UNION ALL returns 9 rows while UNION returns 5, because Bob and Cara appear on both sides and Bob and Eve are repeated within one side. Prefer UNION ALL unless you specifically need deduplication: it is faster and does not hide data-quality problems.
Why do I get 'each UNION query must have the same number of columns'?
Set operations match columns by position, not by name, so both SELECT lists must have the same number of columns with compatible types. The visualizer reproduces this error when the two headers differ in length. Fix it by selecting the same columns in the same order on each side; if one table lacks a column, select a placeholder such as NULL AS phone in its place. The column names in the output always come from the first query.
How do INTERSECT and EXCEPT compare to JOIN and NOT EXISTS?
INTERSECT returns distinct rows present in both inputs and behaves like an INNER JOIN on every column followed by DISTINCT, except that it treats NULL values as equal. EXCEPT returns distinct rows of the first query that are missing from the second, which is the set form of an anti join written with NOT EXISTS; unlike NOT IN, it is safe when the data contains NULLs. MySQL only added INTERSECT and EXCEPT in 8.0.31, Oracle spells EXCEPT as MINUS, and SQL Server, Oracle and SQLite have no ALL variants, which the generated SQL notes for you. Chat2DB can run the generated statement against your real database and show the plan: download it at https://chat2db.ai/download or open https://app.chat2db.ai.
