Follow us: Connect on YouTube Connect on YouTube Connect on YouTube

Pages

Sunday, 26 November 2017

Oracle SQL MINUS Set Operator


MINUS Operator 

Use the MINUS operator to return rows returned by the first query that are not present in the second query (the first SELECT statement MINUS the second SELECT statement).



Guidelines

         The number of columns and the datatypes of the columns being selected by the SELECT statements in the queries must be identical in all the SELECT statements used in the query. The names of the columns need not be identical.
         All of the columns in the WHERE clause must be in the SELECT clause for the MINUS operator to work.


Using the MINUS Operator 

The MINUS operator returns rows returned by the first query from student1.

Take examples from Student1 and Student2 tables 
 
Select * from Student1;



SrNo
Name
101
Name101
102
Name102
 


Select * from Student2;
 


SrNo
Name
102
Name102
103
Name103
 



Consider the following example:

SQL>SELECT * FROM student1
          MINUS
          SELECT * FROM student2;



Output:



SrNo
Name
101
Name101
102
Name102
  






SET Operator Guidelines

         The expressions in the SELECT lists must match in number and data type.
         Parentheses can be used to alter the sequence of execution.
         The ORDER BY clause:
        Can appear only at the very end of the statement
        Will accept the column name, aliases from the first SELECT statement, or the positional notation
 
 
You May Like:


Share this article :

0 comments:

Post a Comment