Interview Preparation mode beta
Funny Facebook Status Funny Facebook Status
Enter your email address

Can you explain the difference between the INTERSECT and EXCEPT operators?

2 Answers

Nice?Vote!
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: sql, ssis, ssas
Table 2 has values: ssrs, java, sql
Except query:
SELECT COL1 FROM Tbl_1 EXCEPT SELECT COL1 FROM tbl_2
GO
This will return ssis, ssas, ssrs, java
answered 1 year ago by Anand (1,440 points)
Nice?Vote!
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.
answered 1 year ago by Anand (1,440 points)

Related questions