dbms_practical_10[1]
dbms_practical_10[1]
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
5. We will now import the required databases to perform nested sub queries in SELECT
clause.
6. Create a database named ‘banking’ and import the banking database into it.
7. Similarly, create another database named ‘university’ and import the university
database into it.
8. After the tables have been imported we can view their structures and tables by
clicking on the Browse button on the topmost toolbar.
9. Running 5 different SQL nested sub queries in select clause on each “Banking,
University and database Project assigned to each student”:
i) In University Database:
1) Find All Students Who Are Advised by an Instructor from a
Specific Department:
SELECT s_ID
FROM advisor
WHERE i_ID IN(SELECT i_ID
FROM instructor
WHERE dept_name=’Biology’;
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
SELECT s_ID
FROM advisor
WHERE i_ID = (SELECT i_ID
FROM advisor
WHERE s_ID = ‘23121’);
3)Find Students Advised by Instructors Who Advise More Than One Student:
SELECT s_ID
FROM advisor
WHERE i_ID IN (SELECT i_ID
FROM advisor
GROUP BY i_ID
HAVING COUNT(s_ID)>1);
4)Find Instructors Who Advise Students with a Specific Set of IDs (e.g.,
Students '23121' and '44553'):
SELECT i_ID
FROM advisor
FROM advisor
GROUP BY i_ID
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
44
SELECT s_ID
FROM advisor
FROM advisor
GROUP BY i_ID
LIMIT 1);
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
SELECT *
FROM account
FROM account
3)Finding an account whose balance matches the maximum balance across all
accounts:
SELECT *
FROM account
WHERE balance = (SELECT MAX(balance)
FROM account);
4)Fetching the account from the branch with the fewest accounts:
SELECT *
FROM account
FROM account
Group by branch_name
LIMIT 1)
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
5)Selecting an account with a balance closest to the highest balance but not
the highest:
SELECT *
FROM account
WHERE balance=(SELECT MAX(balance)
FROM account
WHERE balance<(SELECT MAX(balance) FROM account));
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
2) Find teachers whose subjects include at least one subject taught in Room 414
SELECT *
FROM faculty_info
WHERE SUBJECTS IN (
SELECT SUBJECTS
FROM faculty_info
WHERE ROOM_NO = '414'
);
4) Find all books authored by authors who have written books for Semester 1
SELECT *
FROM books_info
WHERE AUTHOR IN (
SELECT AUTHOR
FROM books_info
WHERE SEMESTER = 1
);
Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :
4)Find all books authored by authors who have written books for Semester 1:
SELECT *
FROM books_info
WHERE AUTHOR IN (
SELECT AUTHOR
FROM books_info
WHERE SEMESTER = 1
);
Page no.
CO23317