Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql query without subquery

Tags:

sql

mysql

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

like image 680
mrjasmin Avatar asked Jun 10 '26 02:06

mrjasmin


1 Answers

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"
like image 85
Matt Dodge Avatar answered Jun 13 '26 08:06

Matt Dodge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!