Intersect Operator
- Last Updated: May 15, 2020
- 1 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Purpose
Returns a single result set. The result set contains rows that are returned by both Select
statements. Duplicates are returned unless the DISTINCT operator is
added.
Syntax
select_statement
INTERSECT [DISTINCT]
select_statement
where:
- DISTINCT
- eliminates duplicate rows from the results.
Notes
- When using the
INTERSECToperator, the Select lists for each Select statement must have the same number of column expressions with the same data types and must be specified in the same order.
Example A
This example has the same number of column expressions, and each column expression, in order, has the same data type.
SELECT last_name, salary, hire_date FROM emp
INTERSECT [DISTINCT]
SELECT name, pay, birth_date FROM person
Example B
This example is not valid because the data types of the column expressions are
different (salary FROM emp has a different data type than last_name
FROM raises). This example does have the same number of column expressions in
each Select statement but the expressions are not in the same order by data type.
SELECT last_name, salary FROM emp
INTERSECT
SELECT salary, last_name FROM raises