Available Tables

Next →
Try our SQL Mastery Course!

INTERSECT and EXCEPT

The INTERSECT and EXCEPT operators are used to compare two query results. Both require the same number of columns with compatible data types.

INTERSECT

Example – Students with both enrollments and scores:

SELECT student_id FROM enrollments
INTERSECT
SELECT student_id FROM scores;

This returns the student_id values that exist in both tables.

EXCEPT

Example – Students who are enrolled but have no score recorded:

SELECT id FROM enrollments
EXCEPT
SELECT id FROM scores;

Key Difference