Time for a break? No? Then here comes the next exercise!
Correlated subqueries can be used to find the best object in a certain category. Here we select orchestras which have the best rating among orchestras coming from the same city:
FROM Orchestras O1
WHERE Rating = (SELECT MAX(Rating) FROM Orchestras O2 WHERE O1.CityOrigin = O2.CityOrigin)
In the subquery, we select the maximal rating for all orchestras which come from the same city as the orchestra in the outer query. Note that we use aliases
O2 to distinguish between subquery orchestra and outer query orchestra. In the outer query we select orchestras which have
Rating equal to the rating found in the subquery.