Can you explain the difference between the INTERSECT and EXCEPT operators?
INTERSECT returns data value common to BOTH queries (queries on the left and right side of the operand). On the other hand, EXCEPT returns the distinct data value from the left query (query on left side of the operand) which does not exist in the right query (query on the right side of the operand).
Example:
Table 1 has values: jim, tony, john
Table 2 has values: Tony, jason, marie
Except query:
SELECT COL1 FROM Tbl_1 EXCEPT SELECT COL1 FROM tbl_2
GO
This will return Jim, John
Can you explain the difference between the INTERSECT and EXCEPT operators?
EXCEPT: Two query expressions are evaluated and the difference between the results will be returned by EXCEPT operator. The result set will have rows returned from the first set of rows except the rows those are also returned from the second set of rows.
INTERSECT: The result of two queries is evaluated and returns the rows which are common to each.