Skip to content
/Chapter 15 · Set Operations
Lesson 15.3·garden_shop
Lesson 15.3

SQL INTERSECT

INTERSECT finds the overlap between two compatible result sets.

INTERSECT returns rows that appear in both result sets. It is a compact way to answer "what values do these two groups have in common?"

Like UNION, it compares the selected rows, so keep the selected columns focused on the value you want to compare.

Pattern
select value_column
from first_table
intersect
select value_column
from second_table

Compare the same shape

Both sides need the same number of columns. If you select a customer name on one side and a supplier name on the other, you are comparing names, not the states they share.

Schema · Garden ShopTable · customers9 columns · 20 rows
Table · customers

One row per customer. Some customers have no phone on file.

9 columns · 20 rows
customer_id intfirst_name textlast_name textemail textphone textcity textstate textsignup_date dateis_active bool
Your task

Return the state values that appear in bothcustomers and suppliers, sorted alphabetically.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: state.
  • Rows: states found in both customers and suppliers.
  • INTERSECT returns the overlap between two compatible result sets.