GATE CS 2007 · SQL Queries

MCQ · 1 mark · Problem DBMS-SQL-0123

Consider the table employee(empId, name, department, salary) and the two queries Q1 ,Q2 below. Assuming that department 5 has more than one employee, and we want to find the employees who get higher salary than anyone in the department 5, which one of the statements is TRUE for any arbitrary employee table?Q1 : Select e.empId
From employee e
Where not exists
   (Select * From employee s where s.department = "5" and
                                   s.salary >=e.salary)
Q2 : Select e.empId
 From employee e
 Where e.salary > Any
(Select distinct salary From employee s Where s.department ="5"
  1. A
    Q1 is the correct query
  2. B
    Q2 is the correct query
  3. C
    Both Q1 and Q2 produce the same answer.
  4. D
    Neither Q1 nor Q2 is the correct query

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

Show the worked solutionOfficial GATE Answer Key: Option A.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/1259/gate2007-61

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