SlideShare a Scribd company logo
1 of 13
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

Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Serverprogrammings guru
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)Ishucs
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLMSB Academy
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functionssinhacp
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Deepam Aggarwal
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)Ankit Dubey
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptxAnkit Rai
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentationNITISH KUMAR
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseSalman Memon
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operatorsAhmed Farag
 

What's hot (20)

Types Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql ServerTypes Of Join In Sql Server - Join With Example In Sql Server
Types Of Join In Sql Server - Join With Example In Sql Server
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
SQL UNION
SQL UNIONSQL UNION
SQL UNION
 
Group By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQLGroup By, Order By, and Aliases in SQL
Group By, Order By, and Aliases in SQL
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
Sql commands
Sql commandsSql commands
Sql commands
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Restricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data BaseRestricting and Sorting Data - Oracle Data Base
Restricting and Sorting Data - Oracle Data Base
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Sql oracle
Sql oracleSql oracle
Sql oracle
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 

Similar to Computer Science:Sql Set Operation

Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)Ehtisham Ali
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL FundamentalsBrian Foote
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptxEllenGracePorras
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxjainendraKUMAR55
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxKrishnansuSenapati
 
Assignment 4
Assignment 4Assignment 4
Assignment 4SneaK3
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for BeginnersAbdelhay Shafi
 

Similar to Computer Science:Sql Set Operation (20)

set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
Sql server ___________ (advance sql)
Sql server  ___________  (advance sql)Sql server  ___________  (advance sql)
Sql server ___________ (advance sql)
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 
MergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptxMergeResult_2024_02_09_08_59_11.pptx
MergeResult_2024_02_09_08_59_11.pptx
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
ADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptxADV PPT 2 LAB.pptx
ADV PPT 2 LAB.pptx
 
Sql wksht-6
Sql wksht-6Sql wksht-6
Sql wksht-6
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Sql slid
Sql slidSql slid
Sql slid
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 

More from St Mary's College,Thrissur,Kerala

Microbiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical MicrobiologyMicrobiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical MicrobiologySt Mary's College,Thrissur,Kerala
 

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

Creative writing and literature
Creative writing and literature Creative writing and literature
Creative writing and literature
 
Magnetic Tape
Magnetic TapeMagnetic Tape
Magnetic Tape
 
Online Data Storage
Online Data StorageOnline Data Storage
Online Data Storage
 
Mathematics:Cryptography
Mathematics:CryptographyMathematics:Cryptography
Mathematics:Cryptography
 
Mathematics:Arithmetical Functions
Mathematics:Arithmetical FunctionsMathematics:Arithmetical Functions
Mathematics:Arithmetical Functions
 
Physical education :Yoga For Stress Relief
Physical education :Yoga For Stress ReliefPhysical education :Yoga For Stress Relief
Physical education :Yoga For Stress Relief
 
Psychology:PAIN: Types, Theories and Assessment of pain
Psychology:PAIN: Types, Theories and  Assessment of pain Psychology:PAIN: Types, Theories and  Assessment of pain
Psychology:PAIN: Types, Theories and Assessment of pain
 
Economics:Functions
Economics:FunctionsEconomics:Functions
Economics:Functions
 
Mathematics:H-Complexity
Mathematics:H-ComplexityMathematics:H-Complexity
Mathematics:H-Complexity
 
Statistics:Probability Theory
Statistics:Probability TheoryStatistics:Probability Theory
Statistics:Probability Theory
 
Statistics:Fundamentals Of Statistics
Statistics:Fundamentals Of StatisticsStatistics:Fundamentals Of Statistics
Statistics:Fundamentals Of Statistics
 
Economics:Public Revenue
Economics:Public RevenueEconomics:Public Revenue
Economics:Public Revenue
 
Economics:Public Debt
Economics:Public  DebtEconomics:Public  Debt
Economics:Public Debt
 
Economics:Poverty-perspectives And Dimensions
Economics:Poverty-perspectives And DimensionsEconomics:Poverty-perspectives And Dimensions
Economics:Poverty-perspectives And Dimensions
 
Economics:Economic Integration
Economics:Economic IntegrationEconomics:Economic Integration
Economics:Economic Integration
 
Economics:Enviornmental Pollution
Economics:Enviornmental Pollution Economics:Enviornmental Pollution
Economics:Enviornmental Pollution
 
Computer Science:JavaScript
Computer Science:JavaScript Computer Science:JavaScript
Computer Science:JavaScript
 
Computer Science:Java jdbc
Computer Science:Java jdbcComputer Science:Java jdbc
Computer Science:Java jdbc
 
Microbiology:General Principles of Food Preservation
Microbiology:General Principles of Food PreservationMicrobiology:General Principles of Food Preservation
Microbiology:General Principles of Food Preservation
 
Microbiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical MicrobiologyMicrobiology:Induction Course-Introduction to Medical Microbiology
Microbiology:Induction Course-Introduction to Medical Microbiology
 

Recently uploaded

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

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