GATE / CS ARCHIVE

GATE CSE 1993 / QUESTION 23

Students taught by Ramesh

Database Management Systems · SQL & Queries · Full GATE CSE 1993 paper

GATE 1993, Q23 5 marks · Descriptive
Report issue

SQL & Queries

Question 23, GATE 1993: STUDENTS(rollno key,sname,saddr), COURSES(cno key,cname), ENROLL(rollno,cno composite key,grade), TEACH(tno,cno composite key,tname). FDs: rollno→sname,saddr; cno→cname; tno→tname; rollno,cno→grade. The reproduced cao/sdaddr spellings are interpreted as cno/saddr. Retrieve roll number and name of students with grade A in at least one course taught by a teacher named Ramesh.
Question 23, GATE 1993: STUDENTS(rollno key,sname,saddr), COURSES(cno key,cname), ENROLL(rollno,cno composite key,grade), TEACH(tno,cno composite key,tname). FDs: rollno→sname,saddr; cno→cname; tno→tname; rollno,cno→grade. The reproduced cao/sdaddr spellings are interpreted as cno/saddr. Retrieve roll number and name of students with grade A in at least one course taught by a teacher named Ramesh.
Question 23, GATE 1993: STUDENTS(rollno key,sname,saddr), COURSES(cno key,cname), ENROLL(rollno,cno composite key,grade), TEACH(tno,cno composite key,tname). FDs: rollno→sname,saddr; cno→cname; tno→tname; rollno,cno→grade. The reproduced cao/sdaddr spellings are interpreted as cno/saddr. Retrieve roll number and name of students with grade A in at least one course taught by a teacher named Ramesh.
Tap to enlarge
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.

Original paper, page 14