activitysolutions_6[1].1_module9_union_intersect_minus
TRANSCRIPT
-
8/7/2019 ActivitySolutions_6[1].1_Module9_Union_Intersect_Minus
1/3
RDBMS Unit: Introduction To RDBMS and SQLModule 9: Union-Intersect-Minus
Exercise 01 Union/Intersect/Minusfunctions against the table
Estimated Completion Time: 45 minutes
OverviewThis exercise will require participants to query on the tables in Oracle SQL PLUSusing the SQL language.
InstructionsQuerying records in tables should be done in Oracle SQL PLUS.
1. In order to proceed with querying records in the tables, login using youruser name created in Exercise 01 and then proceed to use the SEToperators.
Hints1. 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.
-
8/7/2019 ActivitySolutions_6[1].1_Module9_Union_Intersect_Minus
2/3
RDBMS Unit: Introduction To RDBMS and SQLModule 9: Union-Intersect-Minus
Union/Intersect and 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
2) Modify the above query to display duplicate names also.
Solution:
SELECT FIRST_NAME, LAST_NAME FROM INSTRUCTOR_INFO
UNION ALL
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' FROMINSTRUCTOR_INFO UNION
SELECT FIRST_NAME, LAST_NAME, 'STUDENT NAME' FROM STUDENT_INFO
4) Display the instructor id not having any section
Solution:
SELECT INSTRUCTOR_ID FROM INSTRUCTOR_INFO
MINUS
SELECT INSTRUCTOR_ID FROM SECTION_INFO
5) Display the course no having section.
Solution:
SELECT COURSE_NO FROM COURSE_INFO
INTERSECT
SELECT COURSE_NO FROM SECTION_INFO
RDBMS 2 52354326.doc 2007 Accenture. All Rights Reserved.
-
8/7/2019 ActivitySolutions_6[1].1_Module9_Union_Intersect_Minus
3/3
RDBMS Unit: Introduction To RDBMS and SQLModule 9: Union-Intersect-Minus
6) Display a list of courses and section having no students enrolled. Add a new columncalled as status that displays text as 'No Student Enrolled'
Solution:
SELECT COURSE_NO, SECTION_NO, 'NO ENROLLMENTS ' AS STATUS FROMSECTION_INFO MINUS
SELECT COURSE_NO, SECTION_NO, ' NO ENROLLMENTS ' FROMSECTION_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
8) Display the student ids who are enrolled.
Solution:
SELECT STUDENT_ID FROM STUDENT
INTERSECT
SELECT STUDENT_ID FROM ENROLLMENT
RDBMS 3 52354326.doc 2007 Accenture. All Rights Reserved.