ActivitySolutions 6 (1) .1 Module9 Union Intersect Minus
ActivitySolutions 6 (1) .1 Module9 Union Intersect Minus
Module 9: Union-Intersect-Minus
Exercise 01 – Union/Intersect/Minus
functions against the table
Estimated Completion Time: 45 minutes
Overview
This exercise will require participants to query on the tables in Oracle SQL PLUS using the
SQL language.
Instructions
Querying records in tables should be done in Oracle SQL PLUS.
1. In order to proceed with querying records in the tables, login using your user name
created in Exercise 01 and then proceed to use the SET operators.
Hints
1. Ensure the following while creating the queries on the table:
Execute the query in SQL PLUS
After each successful command save the command in the file
To save the file - C:\RDBMS\Day3\UnIntMin.sql append
RDBMS 1 52354326.doc
ã 2007 Accenture. All Rights Reserved.
RDBMS Unit: Introduction To RDBMS and SQL
Module 9: Union-Intersect-Minus
1) Display the first name and last name of both the instructor and student in 1 result set.
Solution:
SELECT FIRST_NAME, LAST_NAME FROM INSTRUCTOR_INFO
UNION
SELECT FIRST_NAME, LAST_NAME FROM STUDENT_INFO
3) Modify the above query to add a column Name to display text as 'Instructor' or 'Student' in each row.
Solution:
SELECT FIRST_NAME, LAST_NAME, ‘INSTRCUTOR NAME' FROM
INSTRUCTOR_INFO UNION
SELECT FIRST_NAME, LAST_NAME, 'STUDENT NAME' FROM STUDENT_INFO
6) Display a list of courses and section having no students enrolled. Add a new column called as status
that displays text as 'No Student Enrolled'
RDBMS 2 52354326.doc
ã 2007 Accenture. All Rights Reserved.
RDBMS Unit: Introduction To RDBMS and SQL
Module 9: Union-Intersect-Minus
Solution:
SELECT COURSE_NO, SECTION_NO, 'NO ENROLLMENTS ' AS STATUS FROM
SECTION_INFO MINUS
SELECT COURSE_NO, SECTION_NO, ' ‘NO ENROLLMENTS ' FROM SECTION_INFO
WHERE SECTION_ID IN
(SELECT SECTION_ID FROM SECTION_INFO
INTERSECT
SELECT SECTION_ID FROM ENROLLMENT_INFO)
7) Display all the zip codes that are present in both the instructor and the student tables.
Solution:
SELECT 'INSTRCUTOR ZIP' ZIP, ZIP FROM INSTRUCTOR_INFO
INTERSECT
SELECT 'INSTRCUTOR ZIP' ZIP, ZIP FROM STUDENT_INFO
RDBMS 3 52354326.doc
ã 2007 Accenture. All Rights Reserved.