26.2. INTERSECT and EXCEPT

Intersection and set difference are part of Standard SQL, but few products have implemented them yet.

The INTERSECT and EXCEPT set operators take two tables and build a new table from them. The two tables must be “union-compatible,” which means that they have the same number of columns, and that each column in the first table has the same data type (or automatically casts to it) as the column in the same position in the second table.

That is, their rows have the same structure, so they can be put in the same final result table. Most implementations will do some data type conversions to create the result table, but this is very implementation dependent, and you should check it out for yourself. Like the UNION, the result ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.