oracle
  1. oracle-minus

Minus - (Oracle Operators)

The minus operator in Oracle is used to subtract the rows that are returned by one query from the rows that are returned by another query. It is used with the select statement to perform set operations on the result sets of two or more select statements.

Syntax

The syntax for using the minus operator in Oracle is as follows:

select column1, column2, ...
from table1
minus
select column1, column2, ...
from table2;

Here, table1 and table2 are the tables from which the rows are to be subtracted. The column names and types must match in both select statements. The minus operator returns only the rows that exist in the first query and not in the second.

Example

Let's assume we have two tables, employees and managers, and we want to find the employees who are not managers. We can use the minus operator as follows:

select employee_id, employee_name
from employees
minus
select manager_id, manager_name
from managers;

This will return the list of employees who are not managers.

Output

The output of the select statement using the minus operator will be the result set of rows that are in the first query and not in the second query.

Explanation

In the above example, we have used the minus operator to subtract the rows returned by the second query from the rows returned by the first query. The resulting set of rows includes only those rows that exist in the first query and not in the second query.

Use

The minus operator is used to subtract the rows that are returned by one query from the rows that are returned by another query. It is useful in situations where you need to find the difference between two sets of rows.

Important Points

  • The minus operator is used to subtract the rows that are returned by one query from the rows that are returned by another query.
  • The column names and types must match in both select statements.
  • The minus operator returns only the rows that exist in the first query and not in the second.

Summary

In summary, the minus operator in Oracle is used to subtract the rows that are returned by one query from the rows that are returned by another query. It is useful in situations where you need to find the difference between two sets of rows. The resulting set of rows will only include those rows that exist in the first query and not in the second.

Published on: