GATE CS 2014 · Set-3 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0093

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');
  1. A
    Names of all the employees with at least one of their customers having a 'GOOD' rating
  2. B
    Names of all the employees with at most one of their customers having a 'GOOD' rating.
  3. C
    Names of all the employees with none of their customers having a 'GOOD' rating.
  4. D
    Names of all the employees with all their customers having a 'GOOD' rating.

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

Show the worked solution\[\boxed{\text{NOT EXISTS (a customer of E not rated GOOD)} \iff \text{every customer of E is GOOD}}\]The subquery finds the customers of E whose rating is not GOOD. E is listed only when there is none, i.e. all of E's customers are rated GOOD (each employee has at least one customer, so this is not vacuous).Answer: D

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