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

PPT
PPT
Les07 (using the set operators)
PPT
PPT
e computer notes - Advanced subqueries
PDF
Oracle SQL Interview Questions for Freshers
PDF
C# Fundamentals - Basics of OOPS - Part 2
PDF
DBMS 5 | MySQL Practice List - HR Schema
PDF
Phl Job Portal Training Guide
Les07 (using the set operators)
e computer notes - Advanced subqueries
Oracle SQL Interview Questions for Freshers
C# Fundamentals - Basics of OOPS - Part 2
DBMS 5 | MySQL Practice List - HR Schema
Phl Job Portal Training Guide

Viewers also liked (11)

PPT
PPT
e computer notes - Subqueries
PPT
Subqueries -Oracle DataBase
PPT
SQL subquery
PPT
13. Query Processing in DBMS
PPT
Javascript
PDF
Sub query_SQL
 
PDF
Relational Database Management System
e computer notes - Subqueries
Subqueries -Oracle DataBase
SQL subquery
13. Query Processing in DBMS
Javascript
Sub query_SQL
 
Relational Database Management System
Ad

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

PPT
PPT
Using the set operators
PPT
plsql Les07
PPT
Les08 set operators by Szabist for the MS and MPM
PDF
Lesson07
PPTX
OPerators.pptx Best topics dbms. Good one
PPTX
MYSQL using set operators
PPTX
Computer Science:Sql Set Operation
PPT
Ch7
PDF
Database management system lecture note.
PPTX
Day-2 SQL Theory_V1.pptx
PPT
Les04 Displaying Data from Multiple Tables.ppt
PPT
e computer notes - From multiple tables
PPT
Introduction to-sql
PPT
Day1_SQL_1 for learning about sql cldarly.ppt
PPT
Advanced Sql Training
PPTX
Oracle: Joins
PPTX
Oracle: Joins
PPT
Displaying Data from Multiple Tables - Oracle Data Base
Using the set operators
plsql Les07
Les08 set operators by Szabist for the MS and MPM
Lesson07
OPerators.pptx Best topics dbms. Good one
MYSQL using set operators
Computer Science:Sql Set Operation
Ch7
Database management system lecture note.
Day-2 SQL Theory_V1.pptx
Les04 Displaying Data from Multiple Tables.ppt
e computer notes - From multiple tables
Introduction to-sql
Day1_SQL_1 for learning about sql cldarly.ppt
Advanced Sql Training
Oracle: Joins
Oracle: Joins
Displaying Data from Multiple Tables - Oracle Data Base
Ad

More from ecomputernotes (20)

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

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Computing-Curriculum for Schools in Ghana
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
Lesson notes of climatology university.
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
2.FourierTransform-ShortQuestionswithAnswers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
GDM (1) (1).pptx small presentation for students
Computing-Curriculum for Schools in Ghana
Module 4: Burden of Disease Tutorial Slides S2 2025
Final Presentation General Medicine 03-08-2024.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
RMMM.pdf make it easy to upload and study
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Classroom Observation Tools for Teachers
Microbial disease of the cardiovascular and lymphatic systems
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
STATICS OF THE RIGID BODIES Hibbelers.pdf

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;