Professional Documents
Culture Documents
In this lab they will learn how to perform queries in optimized way. They perform various query
optimization algorithm and optimized query execution plan before performing queries.
1. Given the STUDENT (S_ID, S_NAME, S_ADDRESS, S_PHONE,
S_DATE_OF_BIRTH), COURSE (C_ID, C_NAME) and STUDENT_COURSE (S_ID,
C_ID) tables
● Find the student ids who are enrolled in Database or Algorithm courses.
Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’Database’ or C_NAME=’Algorithm’);
● Find the phone numbers of students who are enrolled in database course.
Select S_PHONE from STUDENT where S_ID IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’Database’ or C_NAME=’Algorithm’));
● Find the student ids of students who have neither enrolled in database nor in
algorithm course
Select S_ID from STUDENT where S_ID NOT IN
(Select S_ID from STUDENT_COURSE where C_ID IN
(SELECT C_ID from COURSE where C_NAME=’Database’ or C_NAME=’Algorithm’));
● Find the minimum and average age of students from the date of births