Similar questions 1 more →
SQL & Queries



Answer & solution
Answer: Use EXISTS to correlate enrollment and teaching to each student. (no official key was published)
A student qualifies if some enrollment has their roll number and grade A, and some teaching row for that enrollment's course has tname='Ramesh'. The course number is the join between ENROLL and TEACH; names need not be unique teacher identifiers.
SELECT s.rollno, s.sname
FROM STUDENTS AS s
WHERE EXISTS (
SELECT 1 FROM ENROLL AS e
JOIN TEACH AS t ON t.cno=e.cno
WHERE e.rollno=s.rollno
AND e.grade='A' AND t.tname='Ramesh'
);EXISTS yields one truth value for each outer student, so several qualifying courses or several teachers named Ramesh do not duplicate the output. A plain join version would need DISTINCT for that purpose. The COURSES relation is unnecessary because the query does not request a course name or another condition on it. No requirement says the student must have an A in every Ramesh-taught course; replacing EXISTS with universal division would answer a stronger question.
The source TEACH attribute is printed cao but described as course number cno, and its FD list prints sdaddr for saddr. These obvious naming inconsistencies are explicitly normalized in the query rather than treated as extra attributes.