SET OPERATIONS:
Set operations are used to join the results of two (or more) SELECT statements.
FOUR DIFFERENT TYPES OF SET OPERATIONS:
• Union
• Union all
• Intersect
• Intersect all
PREPARED BY
MS. S. NANDHINI -III-B.SC - INFORMATION TECHNOLOGY
UNDER THE GUIDANCE OF
Mrs.P.Anusha M.Sc(IT).,M.Phil.,D.P.T.T.,(Ph.D).,
Assistant professor,
Department of Information Technology,
Bon secours college for women,
Thanjavur.
• SQL supports few set operations which can be performed on the tablle
data.
• These are used to get meaningful results from data stored in the table,
under Different special conditions.
SYNTAX FOR SET OPERATIONS:
<query1><set operator><query 2>
UNION:
UNION is used to combine the results of two or more SELECT statements. However it will
eliminate duplicate rows from its result set.
In case of union, number of columns and data type must be same in both the tables, on which
UNION operation is being applied.
SYNTAX FOR UNION:
• Select column name1, column name 2 from table name1 union select column name1, column
name 2 from table name 2.
EXAMPLE:
Table 1 Table 2 Table1 U table2
UNION ALL:
This operation is similar to union.
but it also shows the duplicate rows.
NAME AGE
Anu 19
seeth
a
20
NAME AGE
Seetha 20
Geetha 21
NAME AGE
Anu 19
Seetha 20
Geetha 21
SYNTAX FOR UNION ALL:
• Select column name1,column name2 from tablename1 union all select column
name1, column name2 from tablename2.
INTERSECT:
Intersect operation is used to combine two SELECT statements, but it only returns the records
which are common from both SELECT statements. In case of intersect the number of Columns
and datatype must be same.
NAME AGE
Anu 19
Seetha 20
Seetha 20
Geetha 21
SYNTAX FOR INTERSECT:
• Select column name1, column name2 from tablename1 intersect select column name
1,column name 2 from tablename2.
EXAMPLE:
INTERSECT ALL:
It is same as INTERSECT, returns all distinct rows selected
by both queries.
NAME AGE
Seetha 19
SYNTAX FOR INTERSECT ALL:
• Select column name1, column name2 from tablename1 intersect all select column
name1, column name2 from tablename 2.
NAME AGE
Seetha 19
Seetha 19
MINUS:
The minus operation combines results of two SELECT statements and return only those in the final
result, which belongs to the final set of the result.

set operators.pptx

  • 1.
    SET OPERATIONS: Set operationsare used to join the results of two (or more) SELECT statements. FOUR DIFFERENT TYPES OF SET OPERATIONS: • Union • Union all • Intersect • Intersect all
  • 2.
    PREPARED BY MS. S.NANDHINI -III-B.SC - INFORMATION TECHNOLOGY UNDER THE GUIDANCE OF Mrs.P.Anusha M.Sc(IT).,M.Phil.,D.P.T.T.,(Ph.D)., Assistant professor, Department of Information Technology, Bon secours college for women, Thanjavur.
  • 3.
    • SQL supportsfew set operations which can be performed on the tablle data. • These are used to get meaningful results from data stored in the table, under Different special conditions.
  • 4.
    SYNTAX FOR SETOPERATIONS: <query1><set operator><query 2> UNION: UNION is used to combine the results of two or more SELECT statements. However it will eliminate duplicate rows from its result set. In case of union, number of columns and data type must be same in both the tables, on which UNION operation is being applied.
  • 5.
    SYNTAX FOR UNION: •Select column name1, column name 2 from table name1 union select column name1, column name 2 from table name 2. EXAMPLE: Table 1 Table 2 Table1 U table2 UNION ALL: This operation is similar to union. but it also shows the duplicate rows. NAME AGE Anu 19 seeth a 20 NAME AGE Seetha 20 Geetha 21 NAME AGE Anu 19 Seetha 20 Geetha 21
  • 6.
    SYNTAX FOR UNIONALL: • Select column name1,column name2 from tablename1 union all select column name1, column name2 from tablename2. INTERSECT: Intersect operation is used to combine two SELECT statements, but it only returns the records which are common from both SELECT statements. In case of intersect the number of Columns and datatype must be same. NAME AGE Anu 19 Seetha 20 Seetha 20 Geetha 21
  • 7.
    SYNTAX FOR INTERSECT: •Select column name1, column name2 from tablename1 intersect select column name 1,column name 2 from tablename2. EXAMPLE: INTERSECT ALL: It is same as INTERSECT, returns all distinct rows selected by both queries. NAME AGE Seetha 19
  • 8.
    SYNTAX FOR INTERSECTALL: • Select column name1, column name2 from tablename1 intersect all select column name1, column name2 from tablename 2. NAME AGE Seetha 19 Seetha 19
  • 9.
    MINUS: The minus operationcombines results of two SELECT statements and return only those in the final result, which belongs to the final set of the result.