3

I need to rewrite this query and I'm not allowed to use a subquery. I need to select the name and color of the parts that are heavier than the wheel.

SELECT name, color
FROM parts
WHERE weight > (SELECT weight FROM parts WHERE name="wheel");

This is the table:

PARTS

ID    NAME    COLOR     WEIGHT    
1     wheel   black     100
2     tire    black     50
3     gear    red       20

Thanks in advance

David LeBauer
  • 31,011
  • 31
  • 115
  • 189
mrjasmin
  • 1,230
  • 6
  • 21
  • 37

3 Answers3

2

Join it with itself

SELECT parts_a.name, parts_a.color 
FROM parts parts_a, parts parts_b
WHERE parts_a.weight > parts_b.weight
   AND parts_b.name = "wheel"
Matt Dodge
  • 10,833
  • 7
  • 38
  • 58
0

You can do with join.

SELECT a.name, a.color 
FROM parts as a left join parts as b on a.ID=b.ID
WHERE a.weight > b.weight
AND b.name = "wheel"
-1

I should write down this query without using subqueries SELECT C.pid FROM Catalog C, Suppliers S WHERE S.sname = ‘Yosemite Sham’ AND C.sid = S.sid AND C.cost ≥ ALL (Select C2.cost FROM Catalog C2, Suppliers S2 WHERE S2.sname = ‘Yosemite Sham’ AND C2.sid = S2.sid)

davis
  • 29
  • 2