SQL SELECT EXCEPT
Syntax:
First SELECT statement
EXCEPT
Second SELECT statement
The EXCEPT clause helps return rows from the first SELECT statement that are not returned by the second SELECT statement. One ore more columns are included in each SELECT statements, depending on what are queried.
Example:
Vehicles1 table:
ID PlateNumber Make Model Color
-----------------------------------------------------------
1 AAA111 Toyota Corolla White
2 BBB222 Honda Odyssey Black
3 CCC333 Nissan Pulsar Green
4 DDD444 BMW i8 White
5 EEE555 Mercedes E 350 Silver
6 FFF666 VinFast VF9 Blue
7 GGG777 Tesla Model X Yellow
8 HHH888 Kia Stonic Red
9 III999 Hyundai IONIQ 5 Silver
10 JJJ000 Mazda CX5 Black
Vehicles2 table:
ID PlateNumber Make Model Color
------------------------------------------------------------
1 FFF666 VinFast VF9 Blue
2 GGG777 Tesla Model X Yellow
3 HHH888 Kia Stonic Red
4 III999 Hyundai IONIQ 5 Silver
5 JJJ000 Mazda CX5 Black
6 KKK111 Ferrari 458 Red
7 LLL222 Lamborghini Urus Silver
8 MMM333 Rolls Royce Phamtom Red
9 NNN444 Bugatti Veyron Blue
10 OOO555 Holden Commorde Orange
The query below finds plate numbers in Vehicles1 but not in Vehicles2
SELECT PlateNumber FROM Vehicles1
EXCEPT
SELECT PlateNumber FROM Vehicles2
Below would be the result of the query:
PlateNumber
-----------
AAA111
BBB222
CCC333
DDD444
EEE555