What is the usage of intersect in SQL?

In SQL, INTERSECT is used to retrieve the intersection of two or more query results. It returns the rows that appear in all query results simultaneously. The syntax for INTERSECT is as follows:

SELECT column1, column2, ...
FROM table1
INTERSECT
SELECT column1, column2, ...
FROM table2;

In this example, the results of two SELECT statements are compared, and only rows that appear in both results will be returned. INTERSECT can be used to filter out data that meets multiple conditions simultaneously. It is important to note that INTERSECT can only be used to compare two query results. If you need to compare multiple results, multiple INTERSECT statements can be used for consecutive comparisons.

Leave a Reply 0

Your email address will not be published. Required fields are marked *