GATE / CS ARCHIVE

GATE CSE 2014 SET 3 / QUESTION 54

GATE CSE 2014 Set 3 Q54

Database Management Systems · SQL & Queries · Full GATE CSE 2014 Set 3 paper

GATE 2014 Set 3, Q54 2 marks · MCQ
Report issue

SQL & Queries

Question 54, GATE 2014: Schemas are employee(empId,empName,empDept) and customer(custId,custName,salesRepId,rating), with salesRepId referencing empId. Every employee sells to at least one customer. Query: SELECT empName FROM employee E WHERE NOT EXISTS (SELECT custId FROM customer C WHERE C.salesRepId=E.empId AND C.rating <> 'GOOD'). It returns names of employees with A at least one GOOD customer; B at most one GOOD customer; C no GOOD customers; D all customers GOOD.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Our answer: D assuming nonnull ratings

Step 1: For a fixed employee, the correlated subquery considers only that employee's customers, and finds rows whose rating is unequal to GOOD. NOT EXISTS keeps the employee exactly when this set is empty. Step 2: If ratings are non-NULL, having no customer rated other than GOOD means every customer is GOOD. The premise guarantees at least one customer, so the intended option is D. Step 3: The source does not declare rating NOT NULL. In SQL, NULL <> 'GOOD' is UNKNOWN, not TRUE, so a NULL-rated customer does not enter the subquery. An employee with only NULL-rated customers is still returned even though all-GOOD is not established. The precise query means “no own customer has a known non-GOOD rating”; retain the official D qualification and existing NULL discrepancy.

Original paper, page 66 · Answer key