CodeBlanks Logo Icon CodeBlanks

Summary - UNION and INTERSECT

Find rows in either or only one list with UNION and EXCEPT.

Summary - UNION and INTERSECT

UNION combines, INTERSECT intersects, EXCEPT takes the difference. All require the same column count.

SELECT name FROM customers
UNION
SELECT name FROM suppliers;

Summary set operation.

name is selected from customers.

Practice Summary - UNION and INTERSECT

Summary: combine customer and supplier names with UNION.

Starter code

query.sql
-- summary union
SELECT name FROM customers

Sample solution

query.sql
SELECT name FROM customers
UNION
SELECT name FROM suppliers;

Expected output

name
Ayşe
Mehmet
ACME

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which keeps duplicates?

  • UNION
  • EXCEPT
  • UNION ALL Correct answer
  • INTERSECT

Explanation: UNION ALL keeps duplicates.

2 Summary - UNION and INTERSECT: match the terms

Term Meaning
UNION union
INTERSECT intersection
EXCEPT difference
UNION ALL with duplicates

All lessons in Intermediate