0
0
PostgreSQLquery~5 mins

INTERSECT and EXCEPT in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SQL INTERSECT operator do?
The INTERSECT operator returns only the rows that appear in both query results. It shows common rows between two SELECT statements.
Click to reveal answer
beginner
What is the purpose of the EXCEPT operator in SQL?
The EXCEPT operator returns rows from the first query that are not present in the second query. It shows what is unique to the first SELECT statement.
Click to reveal answer
intermediate
Can INTERSECT and EXCEPT be used with different numbers of columns in the SELECT statements?
No. Both SELECT statements must have the same number of columns with compatible data types for INTERSECT and EXCEPT to work.
Click to reveal answer
intermediate
How does INTERSECT differ from JOIN in SQL?
INTERSECT returns rows common to both queries as whole rows, while JOIN combines rows based on matching column values, often producing more columns.
Click to reveal answer
beginner
If you want to find customers who bought product A but not product B, which operator would you use?
You would use the EXCEPT operator to find customers in the product A list who are not in the product B list.
Click to reveal answer
What does the INTERSECT operator return?
ARows unique to the first query
BAll rows from the first query
CRows common to both SELECT queries
DAll rows from the second query
Which operator returns rows from the first query that are not in the second?
AEXCEPT
BINTERSECT
CUNION
DJOIN
Can INTERSECT be used if the two SELECT statements have different numbers of columns?
ANo, they must have the same number of columns
BYes, always
COnly if columns have the same names
DOnly if columns are numeric
Which SQL operator would you use to find rows unique to the first query?
AINTERSECT
BEXCEPT
CUNION
DCROSS JOIN
What is a key difference between INTERSECT and JOIN?
AINTERSECT combines columns, JOIN returns common rows
BBoth do the same thing
CJOIN returns unique rows, INTERSECT returns all rows
DINTERSECT returns common rows, JOIN combines rows based on matching columns
Explain how the INTERSECT operator works in SQL and give a simple example.
Think about finding common friends in two friend lists.
You got /3 concepts.
    Describe the EXCEPT operator and when you would use it.
    Imagine subtracting one list from another.
    You got /3 concepts.