EXCEPT Operator - SQL


Overview


The EXCEPT Operator in SQL is used to return the rows from the first SELECT statement that are not present in the second SELECT statement. It effectively subtracts the result set of the second query from the result set of the first query.

Syntax:

SELECT column1, column2
FROM table1
EXCEPT
SELECT column1, column2
FROM table2

SELECT column1, column2, ... FROM table1 specifies the columns to select from the first table.

EXCEPT combines the results of the two SELECT statements, returning only the rows from the first result set that are not present in the second result set.

SELECT column1, column2, ... FROM table2 specifies the columns to select from the second table. The number and data types of columns in both SELECT statements must match.