I've got a table with the schema
Cars(make, model, country, horsepower, doors)
I need to determine which cars in the table have the greatest horsepower (ties are allowed).
My first thought was something like
SELECT model
FROM Cars
WHERE horsepower = MAX(horsepower)
but of course that resulted in a grouping error.
I tried doing various increasingly complicated things with ORDER
and HAVING
that I no longer remember, but had no luck.
Eventually, I solved it by using a subquery:
SELECT model
FROM Cars
WHERE horsepower IN
(SELECT MAX(horsepower) FROM Cars)
but for some reason I can't shake the feeling that this is hacky and that there's a better way to do it (without resorting to a subquery). Suggestions?
For those who care about such things, yes, this is (or, more accurately, was) homework. But I already got the points with my subquery answer, if that makes a difference. At this point, I just want to find out if there was a better way, and if so, what.
One other thing, I doubt it matters for something this simple, but my teacher is using MySQL.