0% found this document useful (0 votes)
2 views

SQL Set Operations

SQL Set operations are used to combine the results of two or more SELECT statements and include Union, Union All, Intersect, and Minus. Union combines results without duplicates, Union All includes duplicates, Intersect returns common rows, and Minus shows rows from the first query not present in the second. Each operation requires the same number of columns and compatible data types in the SELECT statements.

Uploaded by

killerdeepak3333
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Set Operations

SQL Set operations are used to combine the results of two or more SELECT statements and include Union, Union All, Intersect, and Minus. Union combines results without duplicates, Union All includes duplicates, Intersect returns common rows, and Minus shows rows from the first query not present in the second. Each operation requires the same number of columns and compatible data types in the SELECT statements.

Uploaded by

killerdeepak3333
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL SET OPERATIONS

The SQL Set operation is used to combine the


two or more SQL SELECT statements.

Types of Set Operation


Union
Union All
Intersect
Minus
1. UNION OPERATION:

 This is used to combine result set of two or


more select statement without returning any
duplicate record.

To use union operation, each select statement


must have-
1. The same numbers of column selected
2. The same ordering

Syntax: SELECT column_name FROM table1


UNION
 create table bca1(rollnum int primary key,
f_name varchar(10),l_name varchar(10),address
varchar(20));

create table bca2(rollnum int primary key, f_name


varchar(10),l_name varchar(10),address
varchar(20));

1. select f_name,l_name from bca1 union select


f_name,l_name from bca2; // to perform
union on
selected
columns
2. select * from bca1 union select * from bca2; //
2. UNION ALL OPERATION:

 This is used to combine result set of two or


more select statement with duplicate record.

Syntax: SELECT column_name FROM table1


UNION ALL
SELECT column_name FROM table2;
3. INTERSECT OPERATION

It is used to combine two SELECT statements.


The Intersect operation returns the common
rows from both the SELECT statements.

In the Intersect operation, the number of


datatype and columns must be the same.
Syntax: SELECT column_name FROM table1
INTERSECT
SELECT column_name FROM table2;
4. MINUS OPERATION:

It combines the result of two SELECT


statements. Minus operator is used to display
the rows which are present in the first query but
absent in the second query.

It has no duplicates and data arranged in


ascending order by default.

Syntax: SELECT column_name FROM table1


MINUS
SELECT column_name FROM table2;

You might also like