The minus directive is used on two SQL statements. It first finds the results of the first SQL statement and then looks at the results of the second SQL statement. If so, the information is removed, not in the final results. If the result of the second SQL statement does not exist in the result of the first SQL statement, the data is discarded.
The syntax for minus is as follows:
[SQL Statement 1]
Minus
[SQL Statement 2]
We continue to use the same example:
Store_information table
Store_name Sales Date
Los Angeles $1500 jan-05-1999
San Diego $ jan-07-1999
Los Angeles $300 jan-08-1999
Boston $700 jan-08-1999
Internet Sales Form Date Sales
jan-07-1999 $
jan-10-1999 $535
jan-11-1999 $320
jan-12-1999 $750
And we need to know which days there is a store turnover and no network turnover. To achieve this, we use the following SQL statement:
SELECT Date from Store_information
Minus
SELECT Date from Internet_sales
Results:
Date
jan-05-1999
jan-08-1999
"jan-05-1999", "jan-07-1999", and "jan-08-1999" are the results of the "SELECT Date from Store_information". In this case, "jan-07-1999" is present in the result of the "SELECT Date from Internet_sales". So "jan-07-1999" is not in the final result.
Note that under the minus directive, different values are only listed once.