The Minus is an operator in Structured Query Language, which is used with two SELECT queries.
This operator returns only unique records of the first table, not the common records of both tables.
Syntax of Minus operator in Structured Query Language:
The data type and the number of fields must be the same for every SELECT statement connected with the Minus SQL operator.
Example of Minus operator in SQL
To understand the example of Minus operator in Structured query Language, we have to create the two different tables Old_Worker_Info and New_Worker_Info, and insert the records of Workers in both the tables.
The following query creates the Old_Worker_Info table in the Industry Database:
The following INSERT queries insert the records of old workers in the Old_Worker_Info table:
The following query shows the data of the Old_Worker_Info table.
The following query creates the New_Worker_Info table in the Industry Database:
The following INSERT queries insert the records of new workers in the New_Worker_Info table:
Step 4: View the Inserted Data
The following query shows the data of the New_Worker_Info table.
The following query uses the Minus operator with the above tables:
Minus operator with WHERE clause
The WHERE clause can also be used with the Minus operator for filtering the records of the first table.
Syntax of Minus with WHERE clause
Example of Minus with WHERE Clause
The following query shows those records of Workers from the above tables whose salary is greater than and equal to 35000: