Set Operators
Set Operators
Learning Outcomes
- Learn how to perform a
INTERSECT
of two queries. - Learn how to perform a
MINUS
of two queries. - Learn how to perform a
UNION
of two queries. - Learn how to perform a
UNION ALL
of two queries.
Lesson Materials
You can joins rows between two queries by several techniques. They all work by comparing all the columns returned by the top query with all the columns returned by the bottom query.
Unlike joins where you get to specify the columns that the join uses to match values, set operators match the SELECT
-list of the two queries. The two queries must have the same SELECT
-list columns, which is defined by position, column name, and data type. That means your choice of the SELECT
-list columns determines the join conditions between the queries.
INTERSECT
- The
INTERSECT
operator returns the rows found in both queries. UNION
- The
UNION
operator returns the unique set of rows found in both queries. UNION ALL
- The
UNION ALL
operator returns the unique set of rows found in one query but not the other and two copies of the rows found in both queries. MINUS
- The
MINUS
operator returns the rows from the top query not found in the bottom query.