Grokking SQL for Tech Interviews
Ask Author
Back to course home

0% completed

EXCEPT
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

EXCEPT

EXCEPT operation returns the rows that are present in the first querying table but not in the second. MySQL does not natively support the EXCEPT operator, but you can achieve similar results using LEFT JOIN with a NULL check or NOT EXISTS clauses.

Example using the NOT EXISTS approach:

Suppose we have two database tables with the names Customers and Suppliers as shown below:

Now we want to get the rows from Customers that do not exist in Supppliers based on a common column, let's say city :

SELECT * FROM Customers c WHERE NOT EXISTS ( SELECT 1

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible