SlideShare a Scribd company logo
1 of 17
Using SET Operator  http://ecomputernotes.com
Objectives  After completing this lesson, you should be able to do the following:  "  Describe   SET   operators  "  Use a   SET   operator to combine multiple queries  into a single query  "  Control the order of rows returned  http://ecomputernotes.com
The   SET   Operators  A  B  A  B  UNION /UNION ALL  A  B  INTERSECT  A  B  MINUS  http://ecomputernotes.com
Tables Used in This Lesson  The tables used in this lesson are:  "  EMPLOYEES : Provides details regarding all current employees  "J OB_HISTORY:  Records the details of the start date  and end date of the former job, and the job  identification number and department when an  employee switches jobs  http://ecomputernotes.com
The   UNION   Operator  A  B  The   UNION   operator returns results from both queries after eliminating duplications.  http://ecomputernotes.com
Using the   UNION   Operator  Display the current and previous job details of all employees. Display each employee only once.  SELECT employee_id, job_id  FROM  employees  UNION  SELECT employee_id, job_id  FROM  job_history;  «  «  http://ecomputernotes.com
The   UNION ALL   Operator  A  B  The   UNION ALL   operator returns results from both queries, including all duplications.  http://ecomputernotes.com
Using the   UNION ALL   Operator  Display the current and previous departments of  all employees.  SELECT employee_id, job_id, department_id  FRO M   employees  UNION ALL  SELECT employee_id, job_id, department_id  FROM  job_history  ORDER BY  employee_id;  «  «  http://ecomputernotes.com
The   INTERSECT   Operator  A  B  http://ecomputernotes.com
Using the   INTERSECT   Operator  Display the employee IDs and job IDs of employees  who currently have a job title that they held before  beginning their tenure with the company.  SELECT employee_id, job_id  FROM  employees  INTERSECT  SELECT employee_id, job_id  FROM  job_history;  http://ecomputernotes.com
The   MINUS   Operator  A  B
The   MINUS   Operator  Display the employee IDs of those employees who have  not changed their jobs even once.  SELECT employee_id,job_id  FROM  employees  MINUS  SELECT employee_id,job_id FROM  job_history;  «
SET Operator Guidelines  "T he expressions in the  S ELECT  l ists must match in  number and data type.  "P arentheses can be used to alter the sequence of  execution.  "  The   ORDER BY   clause:  Can appear only at the very end of the statement Will accept the column name, aliases from the first SELECT statement, or the positional notation
The Oracle Server and   SET   Operators  "D uplicate rows are automatically eliminated except  in   UNION ALL.  "C olumn names from the first query appear in the  result.  "T he output is sorted in ascending order by default  except in   UNION ALL.
Matching the   SELECT   Statements  Using the   UNION   operator, display the department ID, location, and hire date for all employees.  SELECT department_id, TO_NUMBER(null)  location, hire_date  FROM  employees  UNION  SELECT department_id, location_id,  TO_DATE(null) FROM  departments;
Matching the   SELECT   Statement  "U sing the  U NION  o perator, display the employee ID, job ID, and salary of all employees.  SELECT employee_id, job_id,salary  FROM  employees  UNION  SELECT employee_id, job_id,0  FROM  job_history;  «
Controlling the Order of Rows  Produce an English sentence using two  UNION   operators.  COLUMN a_dummy NOPRINT  SELECT 'sing' AS "My dream", 3 a_dummy  FROM dual  UNION  SELECT 'I''d like to teach', 1  FROM dual  UNION  SELECT 'the world to', 2  FROM dual  ORDER BY 2;

More Related Content

Viewers also liked (11)

Les19
Les19Les19
Les19
 
Subqueries
SubqueriesSubqueries
Subqueries
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Subqueries
SubqueriesSubqueries
Subqueries
 
Set operators
Set  operatorsSet  operators
Set operators
 
Subqueries -Oracle DataBase
Subqueries -Oracle DataBaseSubqueries -Oracle DataBase
Subqueries -Oracle DataBase
 
SQL subquery
SQL subquerySQL subquery
SQL subquery
 
13. Query Processing in DBMS
13. Query Processing in DBMS13. Query Processing in DBMS
13. Query Processing in DBMS
 
Javascript
JavascriptJavascript
Javascript
 
Sub query_SQL
Sub query_SQLSub query_SQL
Sub query_SQL
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 

Similar to e computer notes - Using set operator

e computer notes - Restricting and sorting data
e computer notes -  Restricting and sorting datae computer notes -  Restricting and sorting data
e computer notes - Restricting and sorting data
ecomputernotes
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
ecomputernotes
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statements
ecomputernotes
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
Achmad Solichin
 
e computer notes - From multiple tables
e computer notes - From multiple tablese computer notes - From multiple tables
e computer notes - From multiple tables
ecomputernotes
 
e computer notes - Single row functions
e computer notes - Single row functionse computer notes - Single row functions
e computer notes - Single row functions
ecomputernotes
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating views
ecomputernotes
 
e computer notes - Aggregating data using group functions
e computer notes -  Aggregating data using group functionse computer notes -  Aggregating data using group functions
e computer notes - Aggregating data using group functions
ecomputernotes
 

Similar to e computer notes - Using set operator (20)

Les07
Les07Les07
Les07
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
e computer notes - Restricting and sorting data
e computer notes -  Restricting and sorting datae computer notes -  Restricting and sorting data
e computer notes - Restricting and sorting data
 
Les07
Les07Les07
Les07
 
plsql Les07
plsql Les07 plsql Les07
plsql Les07
 
e computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql pluse computer notes - Producing readable output with i sql plus
e computer notes - Producing readable output with i sql plus
 
e computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statementse computer notes - Writing basic sql select statements
e computer notes - Writing basic sql select statements
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 
Les02
Les02Les02
Les02
 
Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)Les06 (using subqueries to solve queries)
Les06 (using subqueries to solve queries)
 
Les06
Les06Les06
Les06
 
e computer notes - From multiple tables
e computer notes - From multiple tablese computer notes - From multiple tables
e computer notes - From multiple tables
 
Les02
Les02Les02
Les02
 
e computer notes - Single row functions
e computer notes - Single row functionse computer notes - Single row functions
e computer notes - Single row functions
 
Les02.ppt
Les02.pptLes02.ppt
Les02.ppt
 
e computer notes - Creating views
e computer notes - Creating viewse computer notes - Creating views
e computer notes - Creating views
 
SQL- Introduction to MySQL
SQL- Introduction to MySQLSQL- Introduction to MySQL
SQL- Introduction to MySQL
 
e computer notes - Aggregating data using group functions
e computer notes -  Aggregating data using group functionse computer notes -  Aggregating data using group functions
e computer notes - Aggregating data using group functions
 
Restricting and sorting data
Restricting and sorting dataRestricting and sorting data
Restricting and sorting data
 

More from ecomputernotes

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
ecomputernotes
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
ecomputernotes
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
ecomputernotes
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
ecomputernotes
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
ecomputernotes
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
ecomputernotes
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
ecomputernotes
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
ecomputernotes
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
ecomputernotes
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
ecomputernotes
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
ecomputernotes
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
ecomputernotes
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
ecomputernotes
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
ecomputernotes
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
ecomputernotes
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
ecomputernotes
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
ecomputernotes
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
ecomputernotes
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
ecomputernotes
 

More from ecomputernotes (20)

computer notes - Data Structures - 30
computer notes - Data Structures - 30computer notes - Data Structures - 30
computer notes - Data Structures - 30
 
computer notes - Data Structures - 39
computer notes - Data Structures - 39computer notes - Data Structures - 39
computer notes - Data Structures - 39
 
computer notes - Data Structures - 11
computer notes - Data Structures - 11computer notes - Data Structures - 11
computer notes - Data Structures - 11
 
computer notes - Data Structures - 20
computer notes - Data Structures - 20computer notes - Data Structures - 20
computer notes - Data Structures - 20
 
computer notes - Data Structures - 15
computer notes - Data Structures - 15computer notes - Data Structures - 15
computer notes - Data Structures - 15
 
Computer notes - Including Constraints
Computer notes - Including ConstraintsComputer notes - Including Constraints
Computer notes - Including Constraints
 
Computer notes - Date time Functions
Computer notes - Date time FunctionsComputer notes - Date time Functions
Computer notes - Date time Functions
 
Computer notes - Subqueries
Computer notes - SubqueriesComputer notes - Subqueries
Computer notes - Subqueries
 
Computer notes - Other Database Objects
Computer notes - Other Database ObjectsComputer notes - Other Database Objects
Computer notes - Other Database Objects
 
computer notes - Data Structures - 28
computer notes - Data Structures - 28computer notes - Data Structures - 28
computer notes - Data Structures - 28
 
computer notes - Data Structures - 19
computer notes - Data Structures - 19computer notes - Data Structures - 19
computer notes - Data Structures - 19
 
computer notes - Data Structures - 31
computer notes - Data Structures - 31computer notes - Data Structures - 31
computer notes - Data Structures - 31
 
computer notes - Data Structures - 4
computer notes - Data Structures - 4computer notes - Data Structures - 4
computer notes - Data Structures - 4
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
Computer notes - Advanced Subqueries
Computer notes -   Advanced SubqueriesComputer notes -   Advanced Subqueries
Computer notes - Advanced Subqueries
 
Computer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group FunctionsComputer notes - Aggregating Data Using Group Functions
Computer notes - Aggregating Data Using Group Functions
 
computer notes - Data Structures - 16
computer notes - Data Structures - 16computer notes - Data Structures - 16
computer notes - Data Structures - 16
 
computer notes - Data Structures - 22
computer notes - Data Structures - 22computer notes - Data Structures - 22
computer notes - Data Structures - 22
 
computer notes - Data Structures - 35
computer notes - Data Structures - 35computer notes - Data Structures - 35
computer notes - Data Structures - 35
 
computer notes - Data Structures - 36
computer notes - Data Structures - 36computer notes - Data Structures - 36
computer notes - Data Structures - 36
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

e computer notes - Using set operator

  • 1. Using SET Operator http://ecomputernotes.com
  • 2. Objectives After completing this lesson, you should be able to do the following: " Describe SET operators " Use a SET operator to combine multiple queries into a single query " Control the order of rows returned http://ecomputernotes.com
  • 3. The SET Operators A B A B UNION /UNION ALL A B INTERSECT A B MINUS http://ecomputernotes.com
  • 4. Tables Used in This Lesson The tables used in this lesson are: " EMPLOYEES : Provides details regarding all current employees "J OB_HISTORY: Records the details of the start date and end date of the former job, and the job identification number and department when an employee switches jobs http://ecomputernotes.com
  • 5. The UNION Operator A B The UNION operator returns results from both queries after eliminating duplications. http://ecomputernotes.com
  • 6. Using the UNION Operator Display the current and previous job details of all employees. Display each employee only once. SELECT employee_id, job_id FROM employees UNION SELECT employee_id, job_id FROM job_history; « « http://ecomputernotes.com
  • 7. The UNION ALL Operator A B The UNION ALL operator returns results from both queries, including all duplications. http://ecomputernotes.com
  • 8. Using the UNION ALL Operator Display the current and previous departments of all employees. SELECT employee_id, job_id, department_id FRO M employees UNION ALL SELECT employee_id, job_id, department_id FROM job_history ORDER BY employee_id; « « http://ecomputernotes.com
  • 9. The INTERSECT Operator A B http://ecomputernotes.com
  • 10. Using the INTERSECT Operator Display the employee IDs and job IDs of employees who currently have a job title that they held before beginning their tenure with the company. SELECT employee_id, job_id FROM employees INTERSECT SELECT employee_id, job_id FROM job_history; http://ecomputernotes.com
  • 11. The MINUS Operator A B
  • 12. The MINUS Operator Display the employee IDs of those employees who have not changed their jobs even once. SELECT employee_id,job_id FROM employees MINUS SELECT employee_id,job_id FROM job_history; «
  • 13. SET Operator Guidelines "T he expressions in the S ELECT l ists must match in number and data type. "P arentheses can be used to alter the sequence of execution. " The ORDER BY clause: Can appear only at the very end of the statement Will accept the column name, aliases from the first SELECT statement, or the positional notation
  • 14. The Oracle Server and SET Operators "D uplicate rows are automatically eliminated except in UNION ALL. "C olumn names from the first query appear in the result. "T he output is sorted in ascending order by default except in UNION ALL.
  • 15. Matching the SELECT Statements Using the UNION operator, display the department ID, location, and hire date for all employees. SELECT department_id, TO_NUMBER(null) location, hire_date FROM employees UNION SELECT department_id, location_id, TO_DATE(null) FROM departments;
  • 16. Matching the SELECT Statement "U sing the U NION o perator, display the employee ID, job ID, and salary of all employees. SELECT employee_id, job_id,salary FROM employees UNION SELECT employee_id, job_id,0 FROM job_history; «
  • 17. Controlling the Order of Rows Produce an English sentence using two UNION operators. COLUMN a_dummy NOPRINT SELECT 'sing' AS "My dream", 3 a_dummy FROM dual UNION SELECT 'I''d like to teach', 1 FROM dual UNION SELECT 'the world to', 2 FROM dual ORDER BY 2;