Home » Database » Database miscellaneous » Question

Database miscellaneous

  1. 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. Q1 is the correct query
    2. Q2 is the correct query
    3. Both Q1 and Q2 produce the same answer
    4. Neither Q1 nor Q2 is the correct query
Correct Option: B

As per given,
employee (empId, name, department, salary)
This suggests that an employees is to be denoted using the employee Id, name, department, salary
Query1 It selects an employee but does not compute the result as after the ‘where not exists’, it does not have statement to produce the result.
Query2 It selects an employee who gets higher salary than anyone in the department 5. Therefore, the query2 is correct.



Your comments will be displayed only after manual approval.