UGC-NET Dec 2013 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0009

Consider the table student (stuid, name, course, marks). Which one of the following two queries is correct to find the highest marks student in course 5?Q.1. select S.stuid from student S where not exists (select * from student e where e.course = '5' and e.marks \(\geq\) S.marks)Q.2. select S.stuid from student S where S.marks > any (select distinct marks from student S where S.course = 5)
  1. A
    Q.1
  2. B
    Q.2
  3. C
    Both Q.1 and Q.2
  4. D
    Neither Q.1 nor Q.2

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionQ.1: for the top scorer \(t\) of course 5, the subquery finds \(e=t\) itself (\(t.\text{marks}\ge t.\text{marks}\)), so NOT EXISTS is false and \(t\) is dropped. Q.1 returns only students scoring strictly more than everyone in course 5, never the course-5 topper. Wrong.Q.2: "> any" means greater than at least one course-5 mark, i.e. above the course-5 minimum. It returns many students, from any course. Wrong.Neither query finds the highest scorer of course 5 (that would need \(>\) instead of \(\ge\) in Q.1 restricted to course 5, or "\(\ge\) all" in Q.2). The official UGC NET key was (B), which is wrong.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com