GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
717 views

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.

asked in Databases by Veteran (73.2k points)   | 717 views

3 Answers

+9 votes
Best answer

So, an employee whose $ALL$ customers gives him GOOD rating is chosen;

All such employees are chosen.
ans = option D

answered by Veteran (26.8k points)  
edited by
Inner query will result all employees which has atleast one bad rating i.e. it will also include which has good as well as some bad rating

And outer query is asking for employees for which inner query return none .

So if any employee having both bad and good rating then they will not be part of outer query.

So answer is D
+8 votes
(D)

inner query selects "employees with atleast one bad rating"

so negation on the above stmt give -> "employees with all ratings as good"

PS:put a ven diagram and practice for these kind of questions
answered by Loyal (3.1k points)  
kindly shows us your process of coming up with a venn diagram for this.

i think what he means is we can draw a two circles one inside other with inner one representing the literal meaning of inner query and outter one representing the outter query and then figure out the meaning of inner circle wrt to outter one, as the inner circle will be the literal answer.

in this context NOTEXISTS which will give something like A-B venn diag. with A as outter circle and B the inner one, but it marks " a Employee has to be GOOD to be BAD which is confusing " frown

0 votes

T

Try applying quantification rules as above.

Ans(D)."every customer of given employee has given a good rating"

answered ago by (155 points)  
Top Users Jan 2017
  1. Debashish Deka

    7080 Points

  2. Habibkhan

    4676 Points

  3. Vijay Thakur

    4224 Points

  4. saurabh rai

    4014 Points

  5. sudsho

    3990 Points

  6. Arjun

    3138 Points

  7. GateSet

    3088 Points

  8. santhoshdevulapally

    3004 Points

  9. Bikram

    2976 Points

  10. Sushant Gokhale

    2824 Points

Monthly Topper: Rs. 500 gift card

18,813 questions
23,785 answers
51,449 comments
20,130 users