edited by
14,328 views
56 votes
56 votes

In an inventory management system implemented at a trading corporation, there are several tables designed to hold all the information. Amongst these, the following two tables hold information on which items are supplied by which suppliers, and which warehouse keeps which items along with the stock-level of these items.

Supply = (supplierid, itemcode)
Inventory = (itemcode, warehouse, stocklevel)

For a specific information required by the management, following SQL query has been written

Select distinct STMP.supplierid 
From Supply as STMP
Where not unique (Select ITMP.supplierid
                            From Inventory, Supply as ITMP
                            Where STMP.supplierid = ITMP.supplierid
                            And ITMP.itemcode = Inventory.itemcode
                            And Inventory.warehouse = 'Nagpur');


For the warehouse at Nagpur, this query will find all suppliers who

  1. do not supply any item
  2. supply exactly one item
  3. supply one or more items
  4. supply two or more items
edited by

7 Answers

Best answer
36 votes
36 votes
Answer is D) supply two or more items 
The whole query returns the distinct list of suppliers who supply two or more items.
edited by
65 votes
65 votes

Here most important part is "not unique" supplierid .

means supplier supplies more than one

So, from here we can say D) is the answer.

From the inner query  we get 1,3,3,4 as output.

And outer query takes only distinct nonunique item

i.e. 3 here

So, Ans D) supply two or more items

19 votes
19 votes

Lets break query in 2 Parts:

(Select ITMP.supplierid

From Inventory, Supply as ITMP

Where STMP.supplierid = ITMP.supplierid And ITMP.itemcode = Inventory.itemcode And Inventory.warehouse = 'Nagpur') 

Returns suplier id who suplies atleast one item in nagpur city.

Select distinct STMP.supplierid

From Supply as STMP

Where not unique ( 1,2,3,1,4,5 )                                 

Will return only those value which are not unique i.e. atleast 2 time present. 

So Output will be distinct supllier id in nagpur who suplied at least 2 item.

So D is answer

13 votes
13 votes
Answer is d,  nested query ensures that for only  those suppliers it returns true which supplies more than 1 item in which case supplier id in inner query will be repeated for that supplier.
Answer:

Related questions

54 votes
54 votes
4 answers
1