0% found this document useful (1 vote)
117 views3 pages

ActivitySolutions 6 (1) .1 Module9 Union Intersect Minus

This document provides instructions and solutions for exercises using SQL UNION, INTERSECT, and MINUS operators to query tables in an Oracle database. The exercises include combining data from instructor and student tables, finding records that are in one table but not another, and adding additional columns to the result sets. Solutions are provided using the appropriate SQL statements. Trainees are instructed to login to Oracle SQL*Plus and save their queries and results.

Uploaded by

Neha Vijay
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
117 views3 pages

ActivitySolutions 6 (1) .1 Module9 Union Intersect Minus

This document provides instructions and solutions for exercises using SQL UNION, INTERSECT, and MINUS operators to query tables in an Oracle database. The exercises include combining data from instructor and student tables, finding records that are in one table but not another, and adding additional columns to the result sets. Solutions are provided using the appropriate SQL statements. Trainees are instructed to login to Oracle SQL*Plus and save their queries and results.

Uploaded by

Neha Vijay
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

RDBMS Unit: Introduction To RDBMS and SQL

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

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' FROM
INSTRUCTOR_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

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

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.

You might also like