0% found this document useful (0 votes)
34 views5 pages

Prectical 8

The document discusses different SQL set operators including UNION, UNION ALL, INTERSECT, and MINUS. UNION combines results and eliminates duplicates, while UNION ALL includes duplicates. INTERSECT returns only common records between two tables. MINUS returns records that are in the first table but not the second. Examples are provided for each operator using sample tables to demonstrate how each works.

Uploaded by

shivsaicable67
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)
34 views5 pages

Prectical 8

The document discusses different SQL set operators including UNION, UNION ALL, INTERSECT, and MINUS. UNION combines results and eliminates duplicates, while UNION ALL includes duplicates. INTERSECT returns only common records between two tables. MINUS returns records that are in the first table but not the second. Examples are provided for each operator using sample tables to demonstrate how each works.

Uploaded by

shivsaicable67
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/ 5

RDBMS PRACTICAL:-08 ENROLLMENT NUMBER:-226010307005

ALT

PRACTICAL NO: 08
AIM: Implement SQL queries using Set operators like Union, unionall,
Intersect, Minus etc

SQL supports few Set operations which can be performed on the table data. These are
used to get meaningful results from data stored in the table, under different special
conditions.

In this tutorial, we will cover 4 different types of SET operations, along with example:

 UNION
 UNION ALL
 INTERSECT
 MINUS

UNION Operation

UNION is used to combine the results of two or more SELECT statements. However it will
eliminate duplicate rows from its resultset. In case of union, number of columns and
datatype must be same in both the tables, on which UNION operation is being applied.

Example of UNION

The First22005 table, ID Name


1 chintan
2 komal
3 Deepak

The Second22005 table,


ID Name
3 Deepak
4 megha
5 Jayveer
6 Jay
Union SQL query will be,

SELECT * FROM First22005 UNION SELECT * FROM Second22005;

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 1


RDBMS PRACTICAL:-08 ENROLLMENT NUMBER:-226010307005

The result set table will look like,

UNION ALL

This operation is similar to Union. But it also shows the duplicate rows.

Example of Union All

The First22005 table, ID Name


1 chintan
2 komal
3 Deepak
The second22005 table,
ID Name
3 Deepak
4 Megha
5 Jayveer
6 Jay

Union All query will be like,

SELECT * FROM First22005 UNION ALL SELECT * FROM second22005;

The result set table will look like,

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 2


RDBMS PRACTICAL:-08 ENROLLMENT NUMBER:-226010307005

INTERSECT

Intersect operation is used to combine two SELECT statements, but it only retuns the
records which are common from both SELECT statements. In case of Intersect the number
of columns and datatype must be same.

NOTE: MySQL does not support INTERSECT operator.

Example of Intersect

The First22005 table,

ID Name
1 Chintan
2 komal
3 Deepak

The Second22005 table,

ID Name
3 deepak
4 Megha
5 Jayveer
6 Jay

Intersect query will be,


A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 3
RDBMS PRACTICAL:-08 ENROLLMENT NUMBER:-226010307005

SELECT * FROM First22005 INTERSECT SELECT * FROM second22005;

The result set table will look like

MINUS

The Minus operation combines results of two SELECT statements and return only those in
the final result, which belongs to the first set of the result.

Example of Minus

The First22005 table, ID Name


1 Chintan
2 Komal
3 deepak

The Second22005 table, ID Name


3 Deepak
4 Megha
5 Jayveer
6 Jay
Minus query will be,

SELECT * FROM First22005 MINUS SELECT * FROM second22005;


SELECT * FROM second22005 MINUS SELECT * FROM First22005;

The result set table will look like,

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 4


RDBMS PRACTICAL:-08 ENROLLMENT NUMBER:-226010307005

CONCLUSION:
HENCE WE PERFORM SQL QUERIES USING SET OPERATORS LIKE
UNION, UNION ALL, INTERSECT, MINUS ETC.

Progressive Assessment Sheet as per Rubrics


Regular Level of
Attendance Presentation Total
Assessment Understanding

5 5 7 8 25

Sign : Date:

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 5

You might also like