skip to today's puzzle

INTERSECT only keeps rows in both results

INTERSECT compares the complete rows returned by two SELECT statements. A row stays only when that same row appears in both results. Both SELECT statements must return the same number of compatible columns in the same order. Dialect note: MySQL doesn't support INTERSECT — there you'd write it with a JOIN or IN instead.

A tiny example

In plain English: Show me the items that are on the restock list and already in the pantry.

SELECT name
FROM restock_list
INTERSECT
SELECT name
FROM pantry_items;

Query result

name
oat milk

Oat milk is the only item that appears in both the restock list and the pantry.

Related SQL lessons

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle