Home  >  Article  >  Database  >  How to use intersect in oracle

How to use intersect in oracle

下次还敢
下次还敢Original
2024-05-09 21:06:19545browse

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.

How to use intersect in oracle

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:

  • INTERSECT operator will compare rows from different tables Corresponding column value.
  • If the values ​​of all rows are equal for a given column, then the row will be included in the result set.
  • The UNION clause can be used to combine a result set with INTERSECT results from other tables.
  • The column list must be the same in all SELECT statements.

Example:

Suppose we have the following two tables:

Table1:

##1John2Mary3Bob
ID Name

Table2:

##ID123
Address
123 Main St
456 Oak Ave
789 Pine St
Query:

<code>SELECT ID, Name, Address
FROM Table1
INTERSECT
SELECT ID, NULL, Address
FROM Table2;</code>

Result:

##IDNameAddress##1JohnMaryat In this example, the INTERSECT operator returns rows with the same ID value in both Table1 and Table2.
123 Main St 2
456 Oak Ave

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn