Reputation: 75
I would like to know what the difference between an INTERSECT and an AND statement as well as a UNION statement and a OR statement is. Is there a specific scenario where either one is recommended to use and can could I always use a OR/AND instead of an UNION/ INTERSECT ?
Upvotes: 3
Views: 3958
Reputation: 562270
Use AND
or OR
between terms in a WHERE
clause. If the complete boolean expression evaluates as true, then the row is included in the query's result set.
WHERE country = 'Canada' AND age > 21
Use INTERSECT
or UNION
between SELECT
queries. If a row appears in both result sets, or either result set, respectively, then the row is included in the compound query's result set.
SELECT customer_id FROM archived_orders
UNION
SELECT customer_id FROM recent_orders
Upvotes: 5