The INTERSECT clause in SQL is used to combine two SELECT statements but the dataset returned by the INTERSECT statement will be the intersection of the data-sets of the two SELECT statements. In simple words, the INTERSECT statement will return only those rows which will be common to both of the SELECT statements.
The INTERSECT statement will return only those rows present in the red shaded region. i.e. common to both of the data-sets.
Note: The number and type of fields present in the two data-sets must be same and similar.
SELECT column1 , column2 .... FROM table_names WHERE condition INTERSECT SELECT column1 , column2 .... FROM table_names WHERE condition
SELECT ID, NAME, Amount, Date FROM Customers LEFT JOIN Orders ON Customers.ID = Orders.Customer_id INTERSECT SELECT ID, NAME, Amount, Date FROM Customers RIGHT JOIN Orders ON Customers.ID = Orders.Customer_id;
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- SQL | WHERE Clause
- SQL | Union Clause
- SQL | Distinct Clause
- SQL | SELECT TOP Clause
- Data Visualization Using Chartjs and Django
- Rabin Cryptosystem with Implementation
- Introduction to Project Lombok in Java and How to get started?
- Simplified International Data Encryption Algorithm (IDEA)
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- SFML Graphics Library | Quick Tutorial
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
- Goldbach's Weak Conjecture for Odd numbers
- Game Theory (Normal-form Game) | Set 5 (Dominance Property-Mixed Strategy)