Open In App
Related Articles

GATE | GATE-CS-2014-(Set-3) | Question 65

Improve Article
Improve
Save Article
Save
Like Article
Like

Consider the following relational schema:

  employee(empId, empName, empDept)
  customer(custId, custName, salesRepId, rating)

salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?

SELECT empName
       FROM employee E
       WHERE NOT EXISTS ( SELECT custId
                          FROM customer C
                          WHERE C.salesRepId = E.empId
                            AND C.rating <> `GOOD`);

(A) Names of all the employees with at least one of their customers having a ‘GOOD’ rating.
(B) Names of all the employees with at most one of their customers having a ‘GOOD’ rating.
(C) Names of all the employees with none of their customers having a ‘GOOD’ rating.
(D) Names of all the employees with all their customers having a ‘GOOD’ rating.


Answer: (D)

Explanation: If any employee has received rating other than ‘GOOD’ from any of their customers, then there will be some rows returned by the inner query;
And NOT EXISTS will return false so those employees won’t be printed.

Only those employees which have got rating ‘GOOD’ from all of their customers will be printed.

Quiz of this Question

Last Updated : 15 Oct, 2019
Like Article
Save Article
Similar Reads