Consider the following relational schema:
Employee (`underline(empId)`, empName, empDept)
Customer (`underline(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')
The outer query will return the value (names of employees) for a tuple in
relation E, only if
inner query for that tuple will return no tuple (usage of NOT
EXISTS). The inner query will run for every tuple of outer query. It selects
cust-id for an employee e, if
rating of customer is NOT good. Such an employee
should not be selected in the output of
outer query.
So the query will return the names of all those employees whose all customers
have GOOD rating.
Was this answer helpful ?
Submit Solution