1. INTERSECT clause :
As the name suggests, the intersect clause is used to provide the result of the intersection of two select statements. This implies the result contains all the rows which are common to both the SELECT statements.
Syntax :
SELECT column-1, column-2 …… FROM table 1 WHERE….. INTERSECT SELECT column-1, column-2 …… FROM table 2 WHERE…..
Example :
Table 1 containing Employee Details

Table 2 containing details of employees who are provided bonus

Query :
SELECT ID, Name, Bonus FROM table1 LEFT JOIN table2 ON table1.ID = table2.Employee_ID INTERSECT SELECT ID, Name, Bonus FROM table1 RIGHT JOIN table2 ON table1.ID = table2.Employee_ID;
Result :

2. EXCEPT clause :
This works exactly opposite to the INTERSECT clause. The result, in this case, contains all the rows except the common rows of the two SELECT statements.
Syntax :
SELECT column-1, column-2 …… FROM table 1 WHERE….. EXCEPT SELECT column-1, column-2 …… FROM table 2 WHERE…..
Example :
Table 1 containing Employee Details

Table 2 containing details of employees who are provided bonus

Query :
SELECT ID, Name, Bonus FROM table1 LEFT JOIN table2 ON table1.ID = table2.Employee_ID EXCEPT SELECT ID, Name, Bonus FROM table1 RIGHT JOIN table2 ON table1.ID = table2.Employee_ID;
Result :

Recommended Posts:
- SQL | Except Clause
- Difference between Having clause and Group by clause
- SQL | Distinct Clause
- SQL | WHERE Clause
- SQL | SELECT TOP Clause
- SQL | Union Clause
- SQL | WITH clause
- SQL | OFFSET-FETCH Clause
- SQL | LIMIT Clause
- SQL | USING Clause
- SQL | With Ties Clause
- SQL | Sub queries in From Clause
- SQL | ON Clause
- Combining aggregate and non-aggregate values in SQL using Joins and Over clause
- SQL query using COUNT and HAVING clause
- Difference between Where and Having Clause in SQL
- Difference between order by and group by clause in SQL
- Difference between From and Where Clause in SQL
- Distinct clause in MS SQL Server
- Where clause in MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

