• edited by
24,394 views
76 76 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

9 Answers

Best answer
45 45 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
89 89 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

26 26 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 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.
2 2 votes

"Where not unique" clause will choose the tuples where the condition is not unique, ie, there's duplicity.
For 0 items, there can't be duplicity.
For exactly 1 item, it is unique! The clause literally says "where not unique"
For 2 or more items, there's duplicity.

Hence, Option D

2 2 votes

Eg :

     SUPPLY                                         INVENTORY                           

sup_id      itemcode                        itemcode             warehouse

 S1              I1                                 I1                        NAGPUR

 S2              I1                                 I2                        NAGPUR

 S2              I2                                 I3                        MUMBAI

S3               I1

S3               I2

S3               I3

OUTER QUERY : Select distinct STMP.supplierid 
From Supply as STMP  -> Will select a Row of Supplier Table for which Inner Query will EXECUTE (for every Selected Row).

 

INNER QUERY : 

                            Select ITMP.supplierid
                            From Inventory, Supply as ITMP
                            Where STMP.supplierid = ITMP.supplierid
                            And ITMP.itemcode = Inventory.itemcode
                            And Inventory.warehouse = 'Nagpur'

STMP = OUTER SUPPLY TABLE .

ITMP = INNER SUPPLY TABLE.

Inventory, Supply -> CROSS PRODUCT of both tables .

Where STMP.supplierid = ITMP.supplierid -> THIS will match every sup_id from outer table STMP with respective sup_id in Inner Table ITMP.

Where ITMP.itemcode = After we got our supplier , we will match it with Every item he supplied .

And Inventory.warehouse = 'Nagpur' -> But only if location of warehouse is nagpur.

 

RESULT AFTER JOIN : 

inventory JOIN itmp

 

Sup_id .     Itemcode     Warehouse

   S1                I1             NAGPUR

   S2                I1             NAGPUR

   S2                I2             NAGPUR

   S3                I1             NAGPUR

   S3                I2             NAGPUR

   S3                I3             MUMBAI      will not be selected as location is not nagpur .

 

  For S1 NOT UNIQUE will return False as only 1 ROW is TRUE.

  FOR S2 NOT UNIQUE will return True as 2 duplicates of S2 Are Present which makes it not unique.

  FOR S3 NOT UNIQUE will return True as 2 duplicates of S3 Are Present which makes it not unique.

  So we can say that if location is NAGPUR and we find 2 or more items for a supplier , that sup_id will be returned.

So ANS = (D).

 

Answer:
Position:
Show:

Related questions

81 81 votes
6 answers 6 answers
18.0k
18.0k views
Ishrat Jahan asked Nov 3, 2014
18,034 views
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown below:$$\overset{\text{Table:...
63 63 votes
5 answers 5 answers
24.3k
24.3k views
Ishrat Jahan asked Nov 3, 2014
24,257 views
A database table $T_1$ has $2000$ records and occupies $80$ disk blocks. Another table $T_2$ has $400$ records and occupies $20$ disk blocks. These two tables have to be ...
65 65 votes
4 answers 4 answers
15.2k
15.2k views
Ishrat Jahan asked Nov 3, 2014
15,196 views
A database table $T_1$ has $2000$ records and occupies $80$ disk blocks. Another table $T_2$ has $400$ records and occupies $20$ disk blocks. These two tables have to be ...
39 39 votes
2 answers 2 answers
13.7k
13.7k views
Ishrat Jahan asked Nov 3, 2014
13,706 views
In a schema with attributes $A, B, C, D$ and $E$ following set of functional dependencies are given $A \rightarrow B$$A \rightarrow C$$CD \rightarrow E$$B \rightarrow D$...