How do you combine the results of two separate queries? Oracle provides three commands,
that handle combining query results in three different ways.
The following animation shows you the difference between these three commands by using two circles to represent two query result sets, labeled
A and B. The animation shows which portions of the two result sets are returned by combining the two queries with each of the three set
commands: INTERSECT, then UNION, then MINUS.
There are two important rules to follow when using these commands:
Both queries must have matching lists of columns with matching datatypes. In other words, if your first query returns three columns, a
date, a number, and a character column, your second query must also return three columns: a date, a number, and a character column, in
that order. The two queries do not need to use the same column names.
The first query's list of columns is used for the final results set. If two corresponding columns in the two queries have different
lengths, the first query is used to set the length of the final results set. If the second query's column is longer, you may get an
error in your results due to data truncation.
Here is an example of two queries connected with the
ORDER BY 1
This query finds the dates (year and month only) and the employee names that are the same for changes made to the
PRODUCT table and
log entries made to the
In the next lesson, you will learn how to use advanced set operators.
Click the link below to read about the intersect, union, and minus operations
used in Oracle.
Intersect union minus Operations