Skip to main content
SQL โ€ข LESSON 23

SQL UNION

How can we combine rows from two queries and remove duplicate values?

Advancedโฑ 3 Minutesโญ 400 XP
๐Ÿค” THE QUESTION

How can we combine rows from two queries and remove duplicate values?

๐Ÿ’ก WHAT IS IT?

UNION combines result sets from multiple SELECT statements and deduplicates identical rows.

๐ŸŽฏ WHAT IS IT USED FOR?

Merging customer lists, combining full-time and freelance workers into a single unique roster.

๐Ÿ’ป EXAMPLE
SELECT name
FROM employees
UNION
SELECT name
FROM contractors;

๐ŸŽฏ Mission Objectives

Practice typing production-grade SQL code for SQL UNION.

  • โœ“ UNION
  • โœ“ Set Operations
  • โœ“ Deduplication
  • โœ“ Compatible schemas