INTERSECT operator is used to find common rows of two or more tables, that is, rows that appear in all tables at the same time. Usage is as follows: Each SELECT statement specifies a list of columns to compare. INTERSECT compares corresponding column values and includes the row if all values are equal. You can use the UNION clause to combine the results with INTERSECT results from other tables.
INTERSECT usage in Oracle
INTERSECT operator is used to find two or more Common rows of two tables, that is, rows that appear in all tables at the same time. It is a set operation that retrieves rows that meet certain conditions.
Syntax:
<code>SELECT column_list FROM table1 INTERSECT SELECT column_list FROM table2 [UNION] SELECT column_list FROM table3 ...;</code>
Usage instructions:
Example:
Suppose we have the following two tables:
Table1:
ID | Name |
---|---|
John | |
Mary | |
Bob |
Table2:
Address | |
---|---|
123 Main St | |
456 Oak Ave | |
789 Pine St |
<code>SELECT ID, Name, Address
FROM Table1
INTERSECT
SELECT ID, NULL, Address
FROM Table2;</code>
Address | ||
---|---|---|
123 Main St | 2 | |
456 Oak Ave | at In this example, the INTERSECT operator returns rows with the same ID value in both Table1 and Table2. |
The above is the detailed content of How to use intersect in oracle. For more information, please follow other related articles on the PHP Chinese website!