IT lexicon › Database › Difference

Difference

Database På svenska → Updated: 2026-11-11

A set operation returning rows from the first query that don't appear in the second — implemented as EXCEPT in MySQL/PostgreSQL or MINUS in Oracle.

Difference (called MINUS in Oracle or EXCEPT in MySQL/PostgreSQL) is the third classical relational set operation. To find all customers who have never made a purchase, take ALL customers MINUS those appearing in the sales table. It's mathematically simple: rows in the first result but not in the second. It's the inverse of UNION.

Like UNION and INTERSECT, EXCEPT/MINUS is theoretically fundamental but practically less common than one might expect. It can often be replaced with anti-joins or NOT IN clauses, which are frequently faster. Set operations require both queries to have the same columns and compatible types — SQL matches by position, not by name. This historical quirk makes set operations less ergonomic than modern alternatives.

← Back to the lexicon