0% found this document useful (0 votes)
6 views

dbms_practical_10[1]

The document outlines a practical assignment requiring the implementation of five SQL nested subqueries in the WHERE clause for three databases: Banking, University, and an assigned project. It provides detailed steps on setting up the XAMPP server, creating databases, and executing specific SQL queries to retrieve data based on various conditions. Each section includes example queries for the University, Banking, and assigned databases, demonstrating the use of nested subqueries.

Uploaded by

garimadmn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

dbms_practical_10[1]

The document outlines a practical assignment requiring the implementation of five SQL nested subqueries in the WHERE clause for three databases: Banking, University, and an assigned project. It provides detailed steps on setting up the XAMPP server, creating databases, and executing specific SQL queries to retrieve data based on various conditions. Each section includes example queries for the University, Banking, and assigned databases, demonstrating the use of nested subqueries.

Uploaded by

garimadmn
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Date of Practical: Practical 10 Date of Submission :

AIM: Implementation of at least five different SQL nested sub queries in


WHERE clause on each “Banking, University and database Project
assigned to each student”, by running on WAMP/ LAMP /XAMPP /SQL
server.
Procedure:
1. Search for XAMPP Control Panel in your device. Open XAMPP Control Panel
on your device. The XAMPP control window will open.
2. Click on the “Start” button for Apache server and MySQL server. The models will
now be initialised. After the initialisation of models has taken place, the “Stop” button
will appear.
3. Click on the “Admin” button next to the “Stop” button for MySQL server.

4. After clicking on the “Admin” button, you will be redirected to


http://localhost/phpmyadmin/.

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 :

2) Find Students Who Have the Same Advisor as a Given Student


(e.g., Student '23121'):

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

WHERE i_ID IN( SELECT i_ID

FROM advisor

WHERE s_ID IN (‘23121’, ‘44553’)

GROUP BY i_ID

HAVING COUNT(DISTINCT s_ID) = 1)

Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :

44

5)Find Students Advised by Instructors with the Highest Student Count:

SELECT s_ID

FROM advisor

WHERE i_ID=(SELECT i_ID

FROM advisor

GROUP BY i_ID

ORDER BY COUNT (s_ID) DESC

LIMIT 1);

ii) In Banking Database:

1) Fetching the account with the highest balance:

SELECT * FROM account


WHERE balance = (select max (balance ) From account);

Page no.
CO23317
Date of Practical: Practical 10 Date of Submission :

2)Selecting an account with the lowest balance in a specific branch:

SELECT *

FROM account

WHERE balance = (SELECT MIN(balance)

FROM account

WHERE branch_name =‘Downtown’

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

WHERE branch_name =(SELECT branch_name

FROM account

Group by branch_name

ORDER BY COUNT(*) ASC

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));

iii) In Assigned Database:

1) Find teachers who share the same specialization as a specific designation


SELECT *
FROM faculty_info
WHERE SPECIALIZATION IN (
SELECT SPECIALIZATION
FROM faculty_info
WHERE DESIGNATION = 'Professor'
);

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'
);

3) To count the number of teachers grouped by their designation:

SELECT DESIGNATION, COUNT(*) AS TeacherCount


FROM faculty_info
WHERE DESIGNATION IN (
SELECT DISTINCT DESIGNATION
FROM faculty_info
)
GROUP BY DESIGNATION;

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
);

5) To count the number of books grouped by the SUBJECT

SELECT SUBJECT, COUNT(*) AS BookCount


FROM books_info
WHERE SUBJECT IN (
SELECT DISTINCT SUBJECT
FROM books_info
)
GROUP BY SUBJECT;

Page no.
CO23317

You might also like