Set Operator

It allow to combine the results of multile separate queries into a single result set.
    postgres=# select * from dept;   

    SET OPERATOR
    ------------
    UNION
    UNION ALL
    INTERSECT
    EXCEPT

    postgres=# select * from dept;   
    deptno |   dname    |   loc 
    --------+------------+----------      
    10 | ACCOUNTING | NEW YORK      
    20 | RESEARCH   | DALLAS      
    30 | SALES      | CHICAGO      
    40 | OPERATIONS | BOSTON  

    postgres=# select * from dept_tab;   
    deptno |   dname    |   loc 
    --------+------------+----------      
    10 | ACCOUNTING | NEW YORK      
    20 | RESEARCH   | DALLAS      
    50 | DEVELOPER  | LONDON      
    60 | MARKETING  | MEXICO 

UNION :
It returns distinct rows selected by either query.
pg-set-op-1
 
    postgres=# select * from dept 	
    union 	
    select * from dept_tab;   
    
    deptno |   dname    |   loc 
    --------+------------+----------      
    60 | MARKETING  | MEXICO      
    20 | RESEARCH   | DALLAS      
    10 | ACCOUNTING | NEW YORK      
    40 | OPERATIONS | BOSTON      
    30 | SALES      | CHICAGO      
    50 | DEVELOPER  | LONDON 

UNION ALL :
It returns all rows selected by either query.
pg-set-op-2
    postgres=# select * from dept 	
    union all 	
    select * from dept_tab;   
    
    deptno |   dname    |   loc 
    --------+------------+----------      
    10 | ACCOUNTING | NEW YORK      
    20 | RESEARCH   | DALLAS      
    30 | SALES      | CHICAGO      
    40 | OPERATIONS | BOSTON      
    10 | ACCOUNTING | NEW YORK      
    20 | RESEARCH   | DALLAS      
    50 | DEVELOPER  | LONDON      
    60 | MARKETING  | MEXICO 

INTERSECT :
It returns all distinct rows selected by both query.
    postgres=# select * from dept 	
    intersect 	
    select * from dept_tab;   
    
    deptno |   dname    |   loc 
    --------+------------+----------      
    10 | ACCOUNTING | NEW YORK      
    20 | RESEARCH   | DALLAS

EXCEPT :
It returns all distinct rows selected by first query only.
    postgres=# select * from dept 	
    except 	
    select * from dept_tab;   
    
    deptno |   dname    |   loc 
    --------+------------+---------      
    40 | OPERATIONS | BOSTON      
    30 | SALES      | CHICAGO 


(Postgres - Joins)