mrjasmin mrjasmin - 1 year ago 78
MySQL Question

sql query without subquery

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:


1 wheel black 100
2 tire black 50
3 gear red 20

Thanks in advance

Answer Source

Join it with itself

SELECT, parts_a.color 
FROM parts parts_a, parts parts_b
WHERE parts_a.weight > parts_b.weight
   AND = "wheel"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download