Skip to content
Official PYQ · 2007

GATE CS 2007 Q61 — Tuple Calculus and SQL

Explain with AI

Consider the table employee(empId, name, department, salary) and the two queries Q1, Q2Q_1, \, Q_2 below. Assuming that department 55 has more than one employee, and we want to find the employees who get higher salary than anyone in the department 5,5, which one of the statements is TRUE for any arbitrary employee table?

Q1:Q_1:
Select e.empId
From employee e
Where not exists
    (Select * From employee s Where s.department = "5" and s.salary >= e.salary)
Q2:Q_2:
Select e.empId
From employee e
Where e.salary > Any
    (Select distinct salary From employee s Where s.department = "5")
Choose one option
View worked solution

Answer: A

To find the employees who earn a higher salary than anyone in department 5, we need to find employees whose salary is strictly greater than the maximum salary of any employee in department 5.

Analyzing Query Q1Q_1:

Select e.empId
From employee e
Where not exists
    (Select * From employee s Where s.department = "5" and s.salary >= e.salary)
  • The subquery searches for any employee ss in department 5 whose salary is greater than or equal to employee ee's salary (s.salary≥e.salarys.\text{salary} \ge e.\text{salary}).
  • The NOT EXISTS clause ensures that no such employee exists in department 5.
  • Mathematically, this means for every employee ss in department 5, e.salary>s.salarye.\text{salary} > s.\text{salary}.
  • Thus, Q1Q_1 correctly identifies employees who have a higher salary than everyone in department 5.

Analyzing Query Q2Q_2:

Select e.empId
From employee e
Where e.salary > Any
    (Select distinct salary From employee s Where s.department = "5")
  • The > ANY operator returns true if e.salarye.\text{salary} is greater than at least one salary in department 5.
  • This is equivalent to finding employees whose salary is greater than the minimum salary in department 5, which does not satisfy the requirement of being higher than anyone in department 5.

Therefore, only Q1Q_1 is the correct query.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions