Nested Queries
Nested Queries
Using IN / NOT IN
✅ Find students who live in hostels that have at least one vacant room
SELECT student_name
FROM student
WHERE room_no IN (
);
Find students who live in hostels that are NOT full
SELECT student_name
FROM student
WHERE room_no IN (
SELECT room_no
FROM room
);
Find students who are NOT in hostel 'AJAD HOSTEL'
SELECT student_name
FROM student
WHERE room_no IN (
SELECT room_no
FROM room
);
Find hostels that have a capacity greater than at least one hostel in Mumbai
SELECT hostel_name
FROM hostel
WHERE hostel_no IN (
);
Find hostels that have a capacity greater than all hostels in Pune
SELECT hostel_name
FROM hostel
WHERE hostel_no IN (
SELECT hostel_no FROM staff WHERE city = 'Pune'
);
SELECT student_name
FROM student S
WHERE EXISTS (
);
Find students who do NOT have any visitors
SELECT student_name
FROM student S
);
Find all students who have paid rent EXCEPT those staying in AC rooms
SELECT student_name
FROM student
WHERE room_no IN (
);
Find students who have at most one registered contact number
SELECT S.student_name
FROM student S
GROUP BY S.student_id
FROM student S
GROUP BY S.student_id