GATE CSE
First time here? Checkout the FAQ!
x
+9 votes
1.2k 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');  
  1. Names of all the employees with at least one of their customers having a ‘GOOD’ rating. 
  2. Names of all the employees with at most one of their customers having a 'GOOD' rating.
  3. Names of all the employees with none of their customers having a 'GOOD' rating.
  4. Names of all the employees with all their customers having a 'GOOD' rating.
asked in Databases by Veteran (87.2k points)   | 1.2k views

5 Answers

+15 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 (28.7k points)  
selected 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
+10 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.3k 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

@  Aravind Inner query selects All customer, those give bad ratings(not good ratings) ,not the given one u said below-

inner query selects "employees with atleast one bad rating" 

0 votes

T

Try applying quantification rules as above.

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

answered by Active (2.1k points)  
0 votes
If any employee has received rating other than 'good' from some customer,
then there will be some rows returned by the inner query.

And not exists will return false so that employee won't be printed 
only those employees which have got rating good from all their 
customers will be printed.
answered by Loyal (4k points)  
0 votes
Reading the above query in simple English ( ignoring "NOT" ) gives us the desired result:

SELECT EmployeeName WHICH EXISTS { With a GOOD Customer Rating }
answered by Junior (855 points)  


Top Users Sep 2017
  1. Habibkhan

    6504 Points

  2. Arjun

    2254 Points

  3. Warrior

    2234 Points

  4. nikunj

    1980 Points

  5. manu00x

    1726 Points

  6. Bikram

    1726 Points

  7. SiddharthMahapatra

    1718 Points

  8. makhdoom ghaya

    1680 Points

  9. A_i_$_h

    1668 Points

  10. rishu_darkshadow

    1554 Points


25,999 questions
33,568 answers
79,491 comments
31,035 users