SlideShare a Scribd company logo
2
Most read
6
Most read
10
Most read
SQL SET OPERATION
Seena.K
Assistant Professor
Department of Vocational Studies
St. Mary’s College, Thrissur
Sql Set Operations,Seena.k.,St.Mary’s College
SET OPERATION
The SQL Set operation is used to combine the two or more SQL SELECT
statements.
Types of Set operation
1. Union
2. UnionAll
3. Intersect
4. Minus
Sql Set operations,Seena.k.,St.Mary’s College
UNION OPERATOR
 This operator is used to combine two similar queries results into one
single result.
 Here both the queries should have same number of columns and all the
respective columns should be of same datatypes.
 The order of columns in both the queries should also be same.
 This operator eliminates the duplicate records and displays single
record. The resultant records are sorted in ascending order by default.
Sql Set operations,Seena.k.,St.Mary’s College
Rules For Using Union Operator
1. To use this UNION clause, each SELECT statement must have
2. The same number of columns selected
3. The same number of column expressions
4. The same data type and
5. Have them in the same order
6. But they need not have to be in the same length
Sql Set operations,Seena.k.,St.Mary’s College
Syntax For Union Operator
SELECT Column_ name From table1
UNION
SELECT Column_name From table2
 If we need to retain the duplicate value in the resultset,then we have to
use UNION ALL operator
Example For Union Operator
First table Second table
ID NAME
1 Jack
2 Harry
3 Jackson
ID NAME
3 Jackson
4 Stephan
5 David
QUERY : Result Set table
SELECT * FROM First
UNION
SELECT * FROM Second;
Sql Set operations,Seena.k.,St.Mary’s College
ID NAME
1 Jack
2 Harry
3 Jackson
4 Stephan
5 David
UNION ALL OPERATOR
Union All operation is equal to the Union operation.it returns the
set without removing duplication and sorting the data
Syntax
SELECT Column_name FROM table1
UNION ALL
SELECT Column_name FROM table2;
Union Query
SELECT * FROM First
UNION ALL
SELECT * FROM Second
Sql Set operations,Seena.k.,St.Mary’s College
The Result Set table
ID NAME
1 Jack
2 Harry
3 Jackson
3 Jackson
4 Stephan
5 David
Sql Set operations,Seena.k.,St.Mary’s College
Sql Set operations,Seena.k.,St.Mary’s College
INTERSECTION OPERATOR
 operator compares the result of two queries and returns the distinct
rows that are output by both queries Here both the queries should
have same number of columns and all the respective columns should
be of same datatypes.
 Syntax
SELECT column_name From Table1
INTERSECT
SELECT column_name From Table2
Sql Set operations,Seena.k.,St.Mary’s College
Rules for Using Intersect Operator
 The number and the order of the column must be the same in the two
queries
 The data type of the corresponding columns must be in the same data
type group such as numeric or character.
SELECT *FROM First
INTERSECT
SELECT * FROM Second
Result Table :- ID NAME
3 Jackson
Sql Set operations,Seena.k.,St.Mary’s College
MINUS OPERATOR
 This operator is used to display the records that are present only in the
first table or query, and doesn’t present in second table / query. It basically
subtracts the first query results from the second.
 Syntax
SELECT Column_list1,Column_list2 From Table1
MINUS
SELECT Column_lis1,Column_list2 From Table2
Sql Set operations,Seena.k.,St.Mary’s College
MINUS OPERATOR
Minus query
SELECT * FROM First
MINUS
SELECT * From Second
The Result Set Table
ID NAME
1 Jack
2 Harry
Sql Set operations,Seena.k,St.Mar’ys College
REFERENCE
https://www.javapoint.com

More Related Content

What's hot (20)

PPTX
Sql(structured query language)
Ishucs
 
PDF
Database Normalization
Arun Sharma
 
PPT
Sql joins
Berkeley
 
PDF
Normalization in SQL | Edureka
Edureka!
 
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PPTX
SQL(DDL & DML)
Sharad Dubey
 
PPTX
set operators.pptx
Anusha sivakumar
 
PPT
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
PPTX
Aggregate function
Rayhan Chowdhury
 
PPT
MySql slides (ppt)
webhostingguy
 
PPTX
SQL commands
GirdharRatne
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PPTX
4. plsql
Amrit Kaur
 
PPTX
Sql joins
Gaurav Dhanwant
 
PPTX
Relational model
Dabbal Singh Mahara
 
PPTX
Sql and Sql commands
Knowledge Center Computer
 
PPTX
Functional dependencies and normalization
daxesh chauhan
 
PPTX
Joins in SQL
Pooja Dixit
 
Sql(structured query language)
Ishucs
 
Database Normalization
Arun Sharma
 
Sql joins
Berkeley
 
Normalization in SQL | Edureka
Edureka!
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
SQL(DDL & DML)
Sharad Dubey
 
set operators.pptx
Anusha sivakumar
 
Types Of Join In Sql Server - Join With Example In Sql Server
programmings guru
 
Aggregate function
Rayhan Chowdhury
 
MySql slides (ppt)
webhostingguy
 
SQL commands
GirdharRatne
 
Introduction to structured query language (sql)
Sabana Maharjan
 
4. plsql
Amrit Kaur
 
Sql joins
Gaurav Dhanwant
 
Relational model
Dabbal Singh Mahara
 
Sql and Sql commands
Knowledge Center Computer
 
Functional dependencies and normalization
daxesh chauhan
 
Joins in SQL
Pooja Dixit
 

Similar to Computer Science:Sql Set Operation (20)

PPTX
Oracle: Joins
DataminingTools Inc
 
PPTX
Oracle: Joins
oracle content
 
PPTX
Interactive SQL and Advance SQL SQL Performance Tuning.pptx
ssuserb8d5cb
 
PPTX
Sql server ___________ (advance sql)
Ehtisham Ali
 
PPTX
MULTIPLE TABLES
ASHABOOPATHY
 
PPTX
1. dml select statement reterive data
Amrit Kaur
 
PPTX
SQL Fundamentals
Brian Foote
 
PPTX
MYSQL using set operators
Ahmed Farag
 
PPT
Advanced Sql Training
bixxman
 
PPTX
Data Manipulation Language.pptx
EllenGracePorras
 
PPTX
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
PPTX
MergeResult_2024_02_09_08_59_11.pptx
KrishnansuSenapati
 
PDF
Assignment 4
SneaK3
 
PPTX
SQL Server Learning Drive
TechandMate
 
PPTX
SQL Tutorial for Beginners
Abdelhay Shafi
 
PPTX
ADV PPT 2 LAB.pptx
ArjayBalberan1
 
PDF
Sql wksht-6
Mukesh Tekwani
 
PPTX
SQL Query
Imam340267
 
PPTX
More Complex SQL and Concurrency ControlModule 4.pptx
bgscseise
 
PPTX
Sql slid
pacatarpit
 
Oracle: Joins
DataminingTools Inc
 
Oracle: Joins
oracle content
 
Interactive SQL and Advance SQL SQL Performance Tuning.pptx
ssuserb8d5cb
 
Sql server ___________ (advance sql)
Ehtisham Ali
 
MULTIPLE TABLES
ASHABOOPATHY
 
1. dml select statement reterive data
Amrit Kaur
 
SQL Fundamentals
Brian Foote
 
MYSQL using set operators
Ahmed Farag
 
Advanced Sql Training
bixxman
 
Data Manipulation Language.pptx
EllenGracePorras
 
DBMS and SQL(structured query language) .pptx
jainendraKUMAR55
 
MergeResult_2024_02_09_08_59_11.pptx
KrishnansuSenapati
 
Assignment 4
SneaK3
 
SQL Server Learning Drive
TechandMate
 
SQL Tutorial for Beginners
Abdelhay Shafi
 
ADV PPT 2 LAB.pptx
ArjayBalberan1
 
Sql wksht-6
Mukesh Tekwani
 
SQL Query
Imam340267
 
More Complex SQL and Concurrency ControlModule 4.pptx
bgscseise
 
Sql slid
pacatarpit
 
Ad

More from St Mary's College,Thrissur,Kerala (20)

PPTX
Creative writing and literature
St Mary's College,Thrissur,Kerala
 
PPTX
Online Data Storage
St Mary's College,Thrissur,Kerala
 
PPTX
Mathematics:Cryptography
St Mary's College,Thrissur,Kerala
 
PPTX
Mathematics:Arithmetical Functions
St Mary's College,Thrissur,Kerala
 
PPTX
Physical education :Yoga For Stress Relief
St Mary's College,Thrissur,Kerala
 
PPTX
Psychology:PAIN: Types, Theories and Assessment of pain
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Functions
St Mary's College,Thrissur,Kerala
 
PPTX
Mathematics:H-Complexity
St Mary's College,Thrissur,Kerala
 
PPTX
Statistics:Probability Theory
St Mary's College,Thrissur,Kerala
 
PPTX
Statistics:Fundamentals Of Statistics
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Public Revenue
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Public Debt
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Poverty-perspectives And Dimensions
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Economic Integration
St Mary's College,Thrissur,Kerala
 
PPTX
Economics:Enviornmental Pollution
St Mary's College,Thrissur,Kerala
 
PPTX
Computer Science:JavaScript
St Mary's College,Thrissur,Kerala
 
PPTX
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
PPTX
Microbiology:General Principles of Food Preservation
St Mary's College,Thrissur,Kerala
 
PPTX
Microbiology:Induction Course-Introduction to Medical Microbiology
St Mary's College,Thrissur,Kerala
 
Creative writing and literature
St Mary's College,Thrissur,Kerala
 
Mathematics:Cryptography
St Mary's College,Thrissur,Kerala
 
Mathematics:Arithmetical Functions
St Mary's College,Thrissur,Kerala
 
Physical education :Yoga For Stress Relief
St Mary's College,Thrissur,Kerala
 
Psychology:PAIN: Types, Theories and Assessment of pain
St Mary's College,Thrissur,Kerala
 
Mathematics:H-Complexity
St Mary's College,Thrissur,Kerala
 
Statistics:Probability Theory
St Mary's College,Thrissur,Kerala
 
Statistics:Fundamentals Of Statistics
St Mary's College,Thrissur,Kerala
 
Economics:Public Revenue
St Mary's College,Thrissur,Kerala
 
Economics:Public Debt
St Mary's College,Thrissur,Kerala
 
Economics:Poverty-perspectives And Dimensions
St Mary's College,Thrissur,Kerala
 
Economics:Economic Integration
St Mary's College,Thrissur,Kerala
 
Economics:Enviornmental Pollution
St Mary's College,Thrissur,Kerala
 
Computer Science:JavaScript
St Mary's College,Thrissur,Kerala
 
Computer Science:Java jdbc
St Mary's College,Thrissur,Kerala
 
Microbiology:General Principles of Food Preservation
St Mary's College,Thrissur,Kerala
 
Microbiology:Induction Course-Introduction to Medical Microbiology
St Mary's College,Thrissur,Kerala
 
Ad

Recently uploaded (20)

PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 

Computer Science:Sql Set Operation

  • 1. SQL SET OPERATION Seena.K Assistant Professor Department of Vocational Studies St. Mary’s College, Thrissur
  • 2. Sql Set Operations,Seena.k.,St.Mary’s College SET OPERATION The SQL Set operation is used to combine the two or more SQL SELECT statements. Types of Set operation 1. Union 2. UnionAll 3. Intersect 4. Minus
  • 3. Sql Set operations,Seena.k.,St.Mary’s College UNION OPERATOR  This operator is used to combine two similar queries results into one single result.  Here both the queries should have same number of columns and all the respective columns should be of same datatypes.  The order of columns in both the queries should also be same.  This operator eliminates the duplicate records and displays single record. The resultant records are sorted in ascending order by default.
  • 4. Sql Set operations,Seena.k.,St.Mary’s College Rules For Using Union Operator 1. To use this UNION clause, each SELECT statement must have 2. The same number of columns selected 3. The same number of column expressions 4. The same data type and 5. Have them in the same order 6. But they need not have to be in the same length
  • 5. Sql Set operations,Seena.k.,St.Mary’s College Syntax For Union Operator SELECT Column_ name From table1 UNION SELECT Column_name From table2  If we need to retain the duplicate value in the resultset,then we have to use UNION ALL operator
  • 6. Example For Union Operator First table Second table ID NAME 1 Jack 2 Harry 3 Jackson ID NAME 3 Jackson 4 Stephan 5 David QUERY : Result Set table SELECT * FROM First UNION SELECT * FROM Second; Sql Set operations,Seena.k.,St.Mary’s College ID NAME 1 Jack 2 Harry 3 Jackson 4 Stephan 5 David
  • 7. UNION ALL OPERATOR Union All operation is equal to the Union operation.it returns the set without removing duplication and sorting the data Syntax SELECT Column_name FROM table1 UNION ALL SELECT Column_name FROM table2; Union Query SELECT * FROM First UNION ALL SELECT * FROM Second Sql Set operations,Seena.k.,St.Mary’s College
  • 8. The Result Set table ID NAME 1 Jack 2 Harry 3 Jackson 3 Jackson 4 Stephan 5 David Sql Set operations,Seena.k.,St.Mary’s College
  • 9. Sql Set operations,Seena.k.,St.Mary’s College INTERSECTION OPERATOR  operator compares the result of two queries and returns the distinct rows that are output by both queries Here both the queries should have same number of columns and all the respective columns should be of same datatypes.  Syntax SELECT column_name From Table1 INTERSECT SELECT column_name From Table2
  • 10. Sql Set operations,Seena.k.,St.Mary’s College Rules for Using Intersect Operator  The number and the order of the column must be the same in the two queries  The data type of the corresponding columns must be in the same data type group such as numeric or character. SELECT *FROM First INTERSECT SELECT * FROM Second Result Table :- ID NAME 3 Jackson
  • 11. Sql Set operations,Seena.k.,St.Mary’s College MINUS OPERATOR  This operator is used to display the records that are present only in the first table or query, and doesn’t present in second table / query. It basically subtracts the first query results from the second.  Syntax SELECT Column_list1,Column_list2 From Table1 MINUS SELECT Column_lis1,Column_list2 From Table2
  • 12. Sql Set operations,Seena.k.,St.Mary’s College MINUS OPERATOR Minus query SELECT * FROM First MINUS SELECT * From Second The Result Set Table ID NAME 1 Jack 2 Harry
  • 13. Sql Set operations,Seena.k,St.Mar’ys College REFERENCE https://www.javapoint.com