UNION and UNION ALL

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/10

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:30 PM on 9/30/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

11 Terms

1
New cards

UNION

Stacks results from two SELECT statements and removes duplicate rows. Example: a student in Spring and Fall appears once.

2
New cards

UNION ALL

Stacks results and keeps duplicates. Example: a student listed in both semesters appears twice.

3
New cards

UNION requirements

Both SELECT statements need the same number of columns, in the same order, with compatible data types.

4
New cards

UNION example

SELECT full_name FROM Students_Spring2024 UNION SELECT full_name FROM Students_Fall2024;

5
New cards

UNION ALL example

SELECT email FROM Students_Spring2024 UNION ALL SELECT email FROM Students_Fall2024;

6
New cards

ORDER BY with UNION

Put ORDER BY after the second SELECT. Example: UNION SELECT … ORDER BY full_name;

7
New cards

UNION duplicate rule

UNION checks the entire selected row. If one selected value differs, the rows are not duplicates.

8
New cards

UNION mistake

Selecting full_name and academic_year may keep the same student twice if their academic year changed.

9
New cards

Labeling UNION rows

Add a static column to identify the source. Example: SELECT full_name, 'Spring 2024' AS semester FROM Students_Spring2024.

10
New cards

When to use UNION

Use UNION when you want unique combined results. Example: all unique email addresses from Spring and Fall.

11
New cards

When to use UNION ALL

Use UNION ALL when every record matters. Example: all freshman records from both semesters, including repeats.