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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With