SQL INTERSECT vs EXCEPT: Compare Query Results
By Sharon Ben-Moshe · August 21, 2026 · 2 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.
INTERSECT returns shared query rows; EXCEPT returns rows in the first query but not the second. Learn set-operator rules, duplicates, and dialect caveats.
Quick answer
SQL INTERSECT returns rows shared by two compatible query results. SQL EXCEPT returns rows from the first result that do not appear in the second. Both normally remove duplicates unless an ALL variant is used where supported, and column count and compatible types must line up.
FAQs
What is the difference between INTERSECT and EXCEPT in SQL?
INTERSECT returns rows that appear in both query results. EXCEPT returns rows from the first query result that do not appear in the second query result.
Does SQL INTERSECT remove duplicates?
By default, INTERSECT returns distinct rows in databases that implement standard set-operator behavior. Some products also support INTERSECT ALL, which changes duplicate handling; verify the target dialect.
Does column order matter for EXCEPT and INTERSECT?
Yes. Set-operator inputs compare columns positionally, so each SELECT needs the same number of compatible columns in the same business meaning and order.
Is EXCEPT available in every SQL database?
Support varies by database product and version. Check the reference for the exact database that will run the query, especially if portability or ALL variants matter.
Keep reading
SQL LIKE Wildcards: %, _, and ESCAPE Explained
By Sharon Ben-Moshe · Aug 21, 2026
Use SQL LIKE for text patterns without accidental matches. Learn %, _, literal wildcard escaping, case sensitivity, and portable examples.
Read postSQL CAST vs CONVERT: Safe Type Changes Across Databases
By Sharon Ben-Moshe · Aug 21, 2026
CAST turns one SQL data type into another. Learn when CONVERT differs, how invalid values fail, and how to write portable conversions.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.