Question

I need to use a nested query for this problem but I have never used nested queries before. Any help is appreciated. Here's the problem: "List the names of those suppliers who ship a part that weighs more than 200 pounds."

Here's what I have using a Natural Join instead. But the problem requires a nested query.

SELECT Suppliers.sname 

FROM Suppliers NATURAL JOIN Shipments 

       NATURAL JOIN Parts

WHERE Shipments.quantity >= '1'

       AND Parts.weight > '200';

I tried it so far and this is what I have:

SELECT Suppliers.sname

FROM Suppliers, Shipments

WHERE Suppliers.snum = Shipments.snum

        AND Shipments.quantity >= ‘1’

        AND (

            SELECT Parts.weight

            FROM Parts
            ) > ‘200’;

Here's a link to the image of the ERD diagram: http://tinypic.com/r/244qr74/8

Was it helpful?

Solution

I think the reason they want you to use a nested query is that your natural join returns multiple records for a single supplier if that supplier has multiple shipments with parts weighing more than 200 pounds. Now, guessing your keys since they weren't supplied, I think they are looking for something like this:

Select s.sname Supplier
From Suppliers s
Where s.snum In(
               Select Distinct sh.snum 
               From Shipments sh
                   Natural Join Parts p
               Where p.Weight > 200)

EDIT I have updated the query to use the snum key name as displayed on your updated pic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top