SQL Database Set Operation Principles Quiz

SQL Database
0 Passed
0% acceptance

A 50-question quiz exploring UNION, UNION ALL, INTERSECT, and EXCEPT with practical patterns, duplicates, ordering, and dataset comparison.

50 Questions
~100 minutes
1

Question 1

A reporting tool needs to combine two lists of active users—one from a subscription table and one from a trial table. Both contain some overlapping users. Which set operation removes duplicates so each user appears only once in the final result?

A
UNION
B
UNION ALL
C
INTERSECT
D
EXCEPT
2

Question 2

A system merges two sources of product IDs from old and new systems. Since both systems may record the same product multiple times, the team needs an operation that preserves all duplicates while combining the lists. Which operation suits this?

A
UNION ALL
B
UNION
C
INTERSECT
D
FULL JOIN
3

Question 3

An analyst wants to find customers who appear in both a newsletter signup list and a recent purchases list. Which operation isolates values present in both datasets?

A
INTERSECT
B
UNION
C
UNION ALL
D
EXCEPT
4

Question 4

A cleanup task needs to identify email addresses in an old marketing list that do not appear in a newly validated list. Which operation isolates values from the first set that don’t appear in the second?

A
EXCEPT
B
UNION
C
INTERSECT
D
UNION ALL
5

Question 5

Two branch offices maintain their own lists of customer IDs. To build a master view of all unique customers, which operation merges the lists while eliminating repeated IDs?

A
UNION
B
UNION ALL
C
INTERSECT
D
EXCEPT
6

Question 6

Why must the queries used in a UNION return the same number of columns?

A
Because each row must align positionally across both result sets
B
Because databases convert all values to JSON
C
Because UNION automatically adds missing columns
D
Because UNION always sorts by all columns
7

Question 7

Two datasets compare product codes, where one dataset contains text values and the other numeric values. Why might the set operation fail without casting?

A
Set operations require type-compatible columns
B
Set operations require identical table names
C
Set operations require ascending sorting
D
Set operations ignore type differences automatically
8

Question 8

A quality audit checks for overlapping employee IDs reported by two different HR systems. Which set operation directly answers whether an ID appears in both lists?

A
INTERSECT
B
UNION ALL
C
EXCEPT
D
RIGHT JOIN
9

Question 9

A data migration compares new records to old ones. Which operation isolates only the newly added IDs that don’t appear in the legacy dataset?

A
EXCEPT (new EXCEPT old)
B
UNION ALL
C
INTERSECT
D
UNION
10

Question 10

Someone attempts to apply ORDER BY to the first query inside a UNION, but the result ordering looks unexpected. Why?

A
ORDER BY must appear after the final set operation
B
UNION automatically sorts alphabetically
C
UNION ignores numbers completely
D
ORDER BY always applies to individual queries only
11

Question 11

A team compares city lists from two travel apps. They discover that NULL appears in their INTERSECT results only under specific conditions. What explains this behavior?

A
NULL only appears if NULL exists in both result sets
B
NULL always counts as a mismatch
C
NULL uniquely sorts above text values
D
Set operations convert NULL to empty strings
12

Question 12

During a list cleanup, someone uses UNION ALL and notices repeated email addresses. Why does this happen even though both lists were meant to be unique?

A
UNION ALL preserves duplicates exactly as they appear
B
UNION ALL automatically sorts values
C
UNION ALL removes NULL entries only
D
UNION ALL truncates the left query
13

Question 13

A teacher compares two attendance lists to identify students missing from the second list. Which logic correctly describes what EXCEPT accomplishes?

A
It returns items from the first set that are absent in the second
B
It returns only the second set
C
It returns the union of both lists
D
It randomly removes values
14

Question 14

A manager wants to compare employees in North and East divisions to see who belongs to both. Why is INTERSECT the appropriate choice?

A
It identifies records that appear in both input results
B
It lists all division employees
C
It removes all duplicates
D
It shows only records from the first division
15

Question 15

Two queries with different column counts are passed to a UNION operation and the system raises an error. What fundamental rule is being violated?

A
Set operations require identical column counts in each query
B
Queries must share table names
C
Columns must all be numeric
D
Queries must include ORDER BY
16

Question 16

A data warehouse identifies values that only appear in the backup dataset. Which operation, reversed from the typical pattern, reveals extra values in the second query?

A
EXCEPT (backup EXCEPT primary)
B
UNION ALL
C
INTERSECT
D
UNION
17

Question 17

If both lists contain overlapping values and the goal is to count how many duplicate entries exist across both lists combined, why is UNION ALL preferred over UNION?

A
UNION ALL preserves duplicates, allowing count-based analysis
B
UNION ALL removes duplicates fully
C
UNION ALL sorts values alphabetically
D
UNION ALL groups values automatically
18

Question 18

A reporting engine treats set operations as mathematical sets. What common behavior does UNION share with mathematical set union?

A
It removes duplicate values across sets
B
It multiplies each set into combinations
C
It finds only shared values
D
It compares sets by size
19

Question 19

A researcher wants to confirm that two independent surveys captured some of the same respondents. Which set operation will show the overlapping survey IDs?

A
INTERSECT
B
UNION ALL
C
EXCEPT
D
RIGHT JOIN
20

Question 20

If a user mistakenly applies EXCEPT reversed (dataset B EXCEPT dataset A), what is fundamentally being extracted?

A
Values present in B but not in A
B
Values present in A but not in B
C
All unique values from both
D
Values common to both
21

Question 21

A cleanup task uses INTERSECT but notices some entries missing from the result because one of the queries applies a filter. Why does filtering affect the intersection?

A
INTERSECT considers only values returned by each query after filtering
B
Filtering forces UNION behavior
C
Filters always remove duplicates
D
Filters convert NULL to usable values
22

Question 22

When merging two lists using UNION ALL for reporting, why might the final count be misleading without deduplication?

A
UNION ALL may contain repeated values from both sources
B
UNION ALL sorts rows unpredictably
C
UNION ALL ignores rows with NULL
D
UNION ALL removes rows from the larger set
23

Question 23

A team comparing data quality uses EXCEPT to detect values missing from the second dataset, but they notice ordering differences do not matter. Why?

A
Set operations ignore ordering until the final ORDER BY
B
EXCEPT sorts alphabetically by default
C
EXCEPT only works on numeric columns
D
Set operations always reorder columns
24

Question 24

Why does EXCEPT consider NULL values equal when comparing two queries?

A
Set operations treat NULL as a comparable placeholder for equality checks
B
NULL is converted to empty string automatically
C
NULL is always treated as zero
D
NULL cannot appear in set operations
25

Question 25

A query uses UNION to merge two sets but unexpectedly loses some rows because duplicates were removed. Why is this expected?

A
UNION eliminates duplicates as part of its behavior
B
UNION focuses on numeric ordering
C
UNION removes rows containing NULL
D
UNION merges only the larger set
26

Question 26

This query merges customer IDs from two regions. What will the result look like regarding duplicates?

sql
SELECT id FROM region_a
UNION
SELECT id FROM region_b;
A
Combined unique IDs without duplicates
B
All IDs including duplicates
C
IDs only from region_a
D
IDs only present in both regions
27

Question 27

How does this UNION ALL behave when merging product codes from two supplier feeds?

sql
SELECT code FROM supplier_x
UNION ALL
SELECT code FROM supplier_y;
A
All codes from both feeds, preserving duplicates
B
Unique codes only
C
Codes present in both feeds only
D
Codes missing from both feeds
28

Question 28

What does this INTERSECT operation identify between two login history tables?

sql
SELECT user_id FROM logins_week1
INTERSECT
SELECT user_id FROM logins_week2;
A
Users who logged in during both weeks
B
All users from week1
C
Users who logged in only during week2
D
The union of both lists
29

Question 29

The following EXCEPT statement compares dataset A against dataset B. What appears in the result?

sql
SELECT email FROM list_a
EXCEPT
SELECT email FROM list_b;
A
Emails in list_a not present in list_b
B
Emails in both lists
C
Emails unique to list_b
D
All emails combined
30

Question 30

Why does this UNION fail unless both subqueries return the same number of columns?

sql
SELECT name, city FROM contacts
UNION
SELECT name FROM archive;
A
Set operations require matching column counts
B
UNION requires numeric columns only
C
UNION sorts columns automatically
D
UNION cannot include text fields
31

Question 31

This UNION merges two tables of categories. How are NULL values handled?

sql
SELECT category FROM set1
UNION
SELECT category FROM set2;
A
NULL appears only once if present in either set
B
NULL is removed completely
C
NULL becomes an empty string
D
NULL appears once for each table
32

Question 32

How does INTERSECT behave with NULLs in this comparison?

sql
SELECT value FROM a
INTERSECT
SELECT value FROM b;
A
NULL appears only if both sets contain NULL
B
NULL always appears
C
NULL never appears
D
NULL becomes zero automatically
33

Question 33

This EXCEPT operation finds discontinued products. What does it return?

sql
SELECT name FROM all_products
EXCEPT
SELECT name FROM currently_active;
A
Products that exist but are not active
B
Active products only
C
Products appearing in both lists
D
All products from both sets
34

Question 34

What effect does ORDER BY have here?

sql
SELECT id FROM a
UNION
SELECT id FROM b
ORDER BY id;
A
It sorts the entire combined result set
B
It sorts only set b
C
It sorts set a before union
D
It has no effect because UNION forbids ordering
35

Question 35

This pair of sets compares regions. What appears in the output of INTERSECT?

sql
SELECT region FROM r1
INTERSECT
SELECT region FROM r2;
A
Regions appearing in both r1 and r2
B
All regions from both sets
C
Regions exclusive to r1
D
Regions exclusive to r2
36

Question 36

Why does this UNION ALL help track duplicate purchases?

sql
SELECT user_id FROM purchases_jan
UNION ALL
SELECT user_id FROM purchases_jan;
A
It intentionally produces all rows twice to test duplication
B
It removes repeated user IDs
C
It hides duplicate values
D
It sorts by user ID automatically
37

Question 37

This EXCEPT operation checks for missing mapping records. What scenario does it detect?

sql
SELECT code FROM expected_items
EXCEPT
SELECT code FROM actual_items;
A
Items expected but not present in the actual list
B
Items present in both lists
C
Items found only in actual_items
D
All items from both sets
38

Question 38

What does this simple UNION achieve between two attribute lists?

sql
SELECT attr FROM a
UNION
SELECT attr FROM b;
A
A single deduplicated list of attributes
B
A full cross product
C
Attributes only in both sets
D
Attributes only in set a
39

Question 39

Why does this INTERSECT query help validate matching manager IDs?

sql
SELECT manager_id FROM system1
INTERSECT
SELECT manager_id FROM system2;
A
It lists manager IDs found in both systems
B
It removes all manager IDs
C
It lists IDs unique to system1 only
D
It lists IDs unique to system2
40

Question 40

This UNION ALL merges two survey responses. What characteristic defines the output?

sql
SELECT response FROM survey_a
UNION ALL
SELECT response FROM survey_b;
A
All responses preserved including duplicates
B
Only unique responses returned
C
Only overlapping responses returned
D
Responses removed if repeated
41

Question 41

This expression checks for discontinued categories. What does it reveal?

sql
SELECT category FROM previous_year
EXCEPT
SELECT category FROM current_year;
A
Categories present last year but missing this year
B
Categories in both years
C
Categories only in current_year
D
All categories from both lists
42

Question 42

This INTERSECT query checks which device IDs appear in both logs. What does it identify?

sql
SELECT device_id FROM log1
INTERSECT
SELECT device_id FROM log2;
A
Device IDs present in both logs
B
All devices from log1
C
All devices from log2
D
Device IDs missing from both
43

Question 43

Why does this combined query show unique customer names?

sql
SELECT name FROM new_signups
UNION
SELECT name FROM returning_users;
A
UNION removes duplicate names from both lists
B
UNION returns only duplicates
C
UNION filters unmatched rows
D
UNION returns names only from the first query
44

Question 44

What happens when these queries with different numeric types are combined via UNION after casting?

sql
SELECT CAST(price AS DECIMAL(10,2)) FROM a
UNION
SELECT CAST(amount AS DECIMAL(10,2)) FROM b;
A
The sets can merge because columns are made type-compatible
B
The UNION always fails
C
UNION sorts by price only
D
UNION removes all decimal places
45

Question 45

This EXCEPT operation checks which IDs did not move forward to the next phase. What does it find?

sql
SELECT id FROM phase1
EXCEPT
SELECT id FROM phase2;
A
IDs present in phase1 but missing in phase2
B
IDs present in both phases
C
IDs only in phase2
D
All IDs from both phases
46

Question 46

This UNION ALL merges color codes from two palettes. Why might designers use UNION ALL instead of UNION?

sql
SELECT color FROM palette1
UNION ALL
SELECT color FROM palette2;
A
They want to preserve duplicates to analyze usage frequency
B
UNION ALL removes all duplicates
C
UNION ALL forces alphabetical sorting
D
UNION ALL filters out NULL
47

Question 47

How does INTERSECT help validate that two inventory systems register the same SKUs?

sql
SELECT sku FROM inv1
INTERSECT
SELECT sku FROM inv2;
A
It reveals SKUs recorded in both systems
B
It reveals SKUs only in inv1
C
It reveals SKUs only in inv2
D
It reveals SKUs missing from both
48

Question 48

This EXCEPT operation checks for invalid category assignments. What does the result represent?

sql
SELECT category FROM assignments
EXCEPT
SELECT category FROM valid_categories;
A
Categories used but not defined as valid
B
Categories valid in both lists
C
Categories unique to valid_categories
D
All categories from both sets
49

Question 49

This UNION merges two mailing lists. What does the final output guarantee?

sql
SELECT email FROM list1
UNION
SELECT email FROM list2;
A
Each email appears only once even if found in both lists
B
Duplicate emails appear multiple times
C
Only emails in list1 appear
D
Only emails in list2 appear
50

Question 50

This INTERSECT detects customers appearing in both segments. What insight does this provide?

sql
SELECT customer_id FROM segment_a
INTERSECT
SELECT customer_id FROM segment_b;
A
Customers shared across both segments
B
Customers unique to segment_a
C
Customers unique to segment_b
D
All customers from both segments

QUIZZES IN SQL Database