What is the UNION operation in set theory or databases?
UNION combines all unique elements from two sets or tables, removing duplicates to form a single set.
Click to reveal answer
beginner
Define INTERSECTION in the context of databases.
INTERSECTION returns only the elements that appear in both sets or tables.
Click to reveal answer
beginner
What does the DIFFERENCE operation do?
DIFFERENCE returns elements that are in the first set but not in the second set.
Click to reveal answer
intermediate
How does UNION handle duplicate records in database tables?
UNION removes duplicate records, so each record appears only once in the result.
Click to reveal answer
intermediate
Can INTERSECTION be used to find common customers in two sales tables?
Yes, INTERSECTION returns customers present in both sales tables, showing common entries.
Click to reveal answer
Which operation returns all unique records from two tables combined?
AINTERSECTION
BUNION
CDIFFERENCE
DJOIN
✗ Incorrect
UNION combines all unique records from both tables, removing duplicates.
What does INTERSECTION return when applied to two sets?
AElements only in the first set
BElements only in the second set
CElements common to both sets
DAll elements from both sets
✗ Incorrect
INTERSECTION returns only the elements that appear in both sets.
If you want to find records in Table A but not in Table B, which operation do you use?
AUNION
BINTERSECTION
CCROSS JOIN
DDIFFERENCE
✗ Incorrect
DIFFERENCE returns records in the first set (Table A) that are not in the second (Table B).
Does UNION include duplicate records in the result?
ANo, duplicates are removed
BYes, all duplicates are included
COnly duplicates from the first set are included
DOnly duplicates from the second set are included
✗ Incorrect
UNION removes duplicates so each record appears only once.
Which operation would you use to find customers who bought products from both Store A and Store B?
AINTERSECTION
BUNION
CDIFFERENCE
DFULL OUTER JOIN
✗ Incorrect
INTERSECTION finds common customers present in both Store A and Store B.
Explain the difference between UNION, INTERSECTION, and DIFFERENCE operations with examples.
Think about combining lists, finding common friends, or removing items.
You got /4 concepts.
How can UNION, INTERSECTION, and DIFFERENCE be useful in managing data in databases?
Consider scenarios like combining customer lists or comparing inventories.
You got /4 concepts.
Practice
(1/5)
1. Which of the following best describes the union operation in databases?
easy
A. Finds only the common records between two tables
B. Combines all unique records from two tables
C. Returns records from the first table that are not in the second
D. Deletes duplicate records from a table
Solution
Step 1: Understand the union operation
The union operation combines all unique records from two sets or tables, removing duplicates.
Step 2: Compare with other operations
Intersection finds common records, difference finds records in one set but not the other, and deletion removes records.
Final Answer:
Combines all unique records from two tables -> Option B
Quick Check:
Union = Combine unique records [OK]
Hint: Union = all unique items combined [OK]
Common Mistakes:
Confusing union with intersection
Thinking union includes duplicates
Mixing difference with union
2. Which SQL keyword is used to find common records between two tables?
easy
A. UNION
B. DIFFERENCE
C. JOIN
D. INTERSECT
Solution
Step 1: Identify the keyword for common records
The SQL keyword INTERSECT returns only the records common to both tables.
Step 2: Differentiate from other keywords
UNION combines unique records, DIFFERENCE is not a standard SQL keyword, and JOIN combines rows based on a condition.
Final Answer:
INTERSECT -> Option D
Quick Check:
Common records = INTERSECT [OK]
Hint: Common records use INTERSECT keyword [OK]
Common Mistakes:
Using UNION instead of INTERSECT
Confusing JOIN with INTERSECT
Assuming DIFFERENCE is a valid SQL keyword
3. Given two sets A = {1, 2, 3, 4} and B = {3, 4, 5, 6}, what is the result of A INTERSECT B?
medium
A. {3, 4}
B. {1, 2, 3, 4, 5, 6}
C. {1, 2}
D. {5, 6}
Solution
Step 1: Identify common elements in A and B
The common elements between A and B are 3 and 4.
Step 2: Understand INTERSECT operation
INTERSECT returns only the common elements, so the result is {3, 4}.
Final Answer:
{3, 4} -> Option A
Quick Check:
Intersection = common elements [OK]
Hint: Intersection = only common items [OK]
Common Mistakes:
Listing all elements instead of common ones
Confusing intersection with union
Including elements only in one set
4. Consider the SQL query: SELECT * FROM Table1 EXCEPT SELECT * FROM Table2; What is the purpose of the EXCEPT keyword?
medium
A. Returns records in Table1 but not in Table2
B. Returns records in Table2 but not in Table1
C. Returns records common to both tables
D. Returns all records from both tables
Solution
Step 1: Understand the EXCEPT keyword
EXCEPT returns records from the first query that are not present in the second query.
Step 2: Apply to given tables
So, it returns records in Table1 but not in Table2.
Final Answer:
Returns records in Table1 but not in Table2 -> Option A
Quick Check:
Difference = records in first not in second [OK]
Hint: EXCEPT = first table minus second table [OK]
Common Mistakes:
Confusing EXCEPT with UNION
Thinking EXCEPT returns common records
Mixing order of tables in EXCEPT
5. You have two tables: Employees_A with IDs {101, 102, 103, 104} and Employees_B with IDs {103, 104, 105, 106}. You want to find IDs that are in either table but not in both. Which SQL operation gives this result?
hard
A. FULL OUTER JOIN with WHERE condition
B. INTERSECT
C. SYMMETRIC DIFFERENCE using UNION and EXCEPT
D. UNION
Solution
Step 1: Understand the requirement
We want IDs in either table but not in both, which is called symmetric difference.
Step 2: Identify SQL approach
SQL does not have a direct symmetric difference keyword, but it can be done by combining UNION and EXCEPT operations.
Step 3: Explain why other options are incorrect
UNION returns all unique IDs including common ones, INTERSECT returns only common IDs, FULL OUTER JOIN with WHERE can be complex but not direct symmetric difference.
Final Answer:
SYMMETRIC DIFFERENCE using UNION and EXCEPT -> Option C
Quick Check:
Symmetric difference = union minus intersection [OK]
Hint: Symmetric difference = union minus intersection [OK]
Common Mistakes:
Using UNION alone includes common IDs
Using INTERSECT returns only common IDs
Assuming FULL OUTER JOIN alone solves it
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.