0
0
SQLquery~5 mins

INTERSECT for common rows in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL INTERSECT operator do?
It returns only the rows that appear in both SELECT query results, showing common rows between two datasets.
Click to reveal answer
beginner
How is INTERSECT different from UNION in SQL?
INTERSECT returns only rows common to both queries, while UNION returns all unique rows from both queries combined.
Click to reveal answer
intermediate
Can INTERSECT be used with queries that select different columns?
No, both queries must select the same number of columns with compatible data types for INTERSECT to work.
Click to reveal answer
beginner
Write a simple SQL query using INTERSECT to find common employee IDs from two tables: Employees2023 and Employees2024.
SELECT EmployeeID FROM Employees2023 INTERSECT SELECT EmployeeID FROM Employees2024;
Click to reveal answer
intermediate
What happens if there are duplicate rows in the results of the SELECT queries used with INTERSECT?
INTERSECT automatically removes duplicates and returns only distinct common rows.
Click to reveal answer
What does the INTERSECT operator return in SQL?
AAll rows from the first SELECT query
BRows common to both SELECT queries
CAll rows from both SELECT queries combined
DRows unique to the first SELECT query
Which condition must be true for two SELECT queries to be used with INTERSECT?
AThey must select the same number of columns with compatible data types
BThey must select different columns
CThey must use different tables
DThey must have WHERE clauses
If one SELECT query returns duplicate rows, how does INTERSECT handle them?
ADuplicates cause an error
BDuplicates are kept as is
CDuplicates are removed; only distinct common rows are returned
DDuplicates are returned only from the first query
Which SQL operator would you use to find rows that appear in both tables?
AINTERSECT
BUNION
CEXCEPT
DJOIN
What is the result of this query? SELECT id FROM A INTERSECT SELECT id FROM B;
AIDs present only in table A
BAll IDs from table A
CAll IDs from table B
DIDs present in both tables A and B
Explain in your own words what the INTERSECT operator does in SQL and when you might use it.
Think about comparing two lists and finding what they share.
You got /3 concepts.
    Describe the difference between INTERSECT and UNION in SQL with an example scenario for each.
    Consider when you want only shared data vs all data combined.
    You got /3 concepts.