retagged
38,557 views
68 votes
68 votes

Consider the following relational schema:

$\text{Suppliers}(\underline{\text{sid:integer}},\text{ sname:string, city:string, street:string})$ 

$\text{Parts}(\underline{\text{pid:integer}}, \text{ pname:string, color:string})$ 

$\text{Catalog}(\underline {\text{sid:integer, pid:integer}}, \text{cost:real})$

Consider the following relational query on the above database:

SELECT	S.sname
FROM    Suppliers S
WHERE S.sid NOT IN (SELECT C.sid 
                    FROM Catalog C 
                    WHERE C.pid NOT IN (SELECT P.pid 
                                        FROM Parts P 
                                        WHERE P.color<>'blue'))

Assume that relations corresponding to the above schema are not empty. Which one of the following is the correct interpretation of the above query?

  1. Find the names of all suppliers who have supplied a non-blue part.

  2. Find the names of all suppliers who have not supplied a non-blue part.

  3. Find the names of all suppliers who have supplied only non-blue part.

  4. Find the names of all suppliers who have not supplied only blue parts.

retagged

8 Answers

0 votes
0 votes

The subquery “SELECT P.pid FROM Parts P WHERE P.color<> ‘blue’” gives pids of parts which are not blue. The bigger subquery “SELECT C.sid FROM Catalog C WHERE C.pid NOT IN (SELECT P.pid FROM Parts P WHERE P.color<> ‘blue’)” gives sids of all those suppliers who have supplied blue parts. The complete query gives the names of all suppliers who have supplied a non-blue part

source - http://www.geeksforgeeks.org/gate-gate-cs-2009-question-55/

and in made easy book they also given A so please confirm and i also think A because in your answer also you have said 

"Selects suppliers who have not supplied any blue parts." so in other words it can be said as  names of all suppliers who have supplied a non-blue part. and that is option A

0 votes
0 votes

I think the actual result of the query is –

If any supplier supplies any part then it must colour other than blue .

So no answer matches that requirment.

0 votes
0 votes
SELECT P.pid FROM Parts P WHERE P.color<>'blue'

means select all those parts whose color is not blue

 

SELECT C.sid 
FROM Catalog C 
WHERE C.pid NOT IN (SELECT P.pid 
                    FROM Parts P 
                    WHERE P.color<>'blue')

means select all those suppliers who have not supplied any non-blue part => Select all those suppliers who have supplied only blue parts.

 

 

SELECT	S.sname
FROM    Suppliers S
WHERE S.sid NOT IN (SELECT C.sid 
                    FROM Catalog C 
                    WHERE C.pid NOT IN (SELECT P.pid 
                                        FROM Parts P 
                                        WHERE P.color<>'blue'))

Select all those suppliers who have not supplied only blue parts. So D is correct.

A should be incorrect since it this query also includes those suppliers who have supplied no part, as they have also not supplied only blue parts. However option A prints only names of those suppliers who have supplied at least 1 part.

 

 

Answer:

Related questions

62 votes
62 votes
6 answers
1
40 votes
40 votes
5 answers
2
Kathleen asked Sep 22, 2014
43,559 views
What is the maximum height of any AVL-tree with $7$ nodes? Assume that the height of a tree with a single node is $0$.$2$$3$$4$$5$
30 votes
30 votes
2 answers
4