Other Compound Operations

Some SQL-based databases include a wider range of operations that can be performed on two query result sets. These are MINUS or EXCEPT, in which the result contains only the rows from the first result that do not appear in the second, and INTERSECT, in which the result contains only rows that appear in both results.

MySQL does not understand these keywords, but there are ways to perform these operations using other techniques.

Performing a MINUS

The MINUS operator usually is placed between two queries. The result of the first query is returned, excluding any identical rows that are produced by the second query.

Using a similar example to the others in this chapter, you could use MINUS to find only first_name values ...

Get Sams Teach Yourself MySQL 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.