4

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 ?

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • INTERSECT and UNION are set operators. AND and OR are logical operators. there is no direct relationship between these, so your question doesn't make sense. please rephrase and add more details. – SQLRaptor Mar 04 '19 at 18:10
  • All four operators are useful, so there is rule that you should use one or the other. That said, your question seems too broad in my opinion. – Gordon Linoff Mar 04 '19 at 18:48
  • 2
    While I respect those who hold some negative opions towards this question, I think it does expose some typical misunderstanding in SQL, in particular for beginners. So this question does have some merit to be raised. – Jinghui Niu Dec 11 '19 at 05:58

1 Answers1

5

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
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828