How is the MINUS function used in Oracle?
The MINUS function in Oracle database is used to exclude the results of one query from another. It returns all rows that exist in the first query but not in the second query.
The syntax for the MINUS function is as follows:
Retrieve the columns specified from table1, excluding any rows that are also found in table2.
Table1 and Table2 are the names of the tables being queried, and Column1, Column2, and so on are the names of the columns to be queried. The number of columns and data types of the results from the two queries must be the same.
The MINUS function works by combining two query results and removing all rows that are present in the second query result. It is similar to the “EXCEPT” operator in SQL.
Below is an example:
Retrieve the employee details where the employee is not a manager.
This query will return the employee_id, first_name, and last_name of all employees that exist in the “employees” table but not in the “managers” table.