0% found this document useful (0 votes)
7 views2 pages

Set Operator Notes

The document explains SQL set operators that combine results from two queries, including Union, Union All, Intersect, and Minus. Union combines results while eliminating duplicates, Union All includes all records without removing duplicates, Intersect returns common values, and Minus shows rows present in the first query but not in the second. Each operator has specific syntax and rules regarding the number of columns and data types that must match.

Uploaded by

chotuwazir1256
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Set Operator Notes

The document explains SQL set operators that combine results from two queries, including Union, Union All, Intersect, and Minus. Union combines results while eliminating duplicates, Union All includes all records without removing duplicates, Intersect returns common values, and Minus shows rows present in the first query but not in the second. Each operator has specific syntax and rules regarding the number of columns and data types that must match.

Uploaded by

chotuwazir1256
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Set Operators

 Special operators which combines the result of two queries into a single result.
 SQL consists of Set operators like
 Union
 Union All
 Intersect
 Minus
Set Operators – Union
 Used to combine the results of two select statements.
 A Union combines the results of two or more quires into one table.
 It eliminates duplicate rows from its result.
 In case of Union, number of columns and data type must be same in both the tables.
Rules:-
 The number of column in each SELECT statement must match.
 The data types in the columns should be same.
 The columns in each select statement must be in the same order.
 Must have the same expressions and aggregate function in each SELECT statement.
 The UNION operator selects only distinct values by default and it doesn’t select
duplicate values.
Union Syntax & Example
Syntax
Select * from table 1
Union
Select * from table2;
Example
Select name from emp
Union
Select name from cust;
Union All
 This operator combines all records from both the queries.
 It does not avoid the duplicate entries.
Syntax
Select * from table 1
Union all
Select * from table2;
Example
Select name from emp
Union
Select name from cust;

Intersect
 It is used to select common values in a column from tables.
 It is used to combine two SELECT statements, but it only returns the records which
are common from both statements.
Syntax
Select * from table 1
intersect
Select * from table2;
Example
Select name from emp
intersect
Select name from cust;

Minus
 It displays the rows which are present in the first query but absent in the second
query with no duplicated.
 It is used to select value which is present in one table but not in another.
Syntax
Select * from table 1
minus
Select * from table2;
Example
Select name from emp
minus
Select name from cust;

You might also like