Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Very simple subqueries
Subqueries with multiple results
Correlated subqueries
18. The operator ANY in correlated subqueries
Other subqueries

Instruction

Okay! One more thing – you can also use the operator ANY in your correlated subqueries. Just take a look:

SELECT *
FROM hiking_trip
WHERE price < ANY (
  SELECT price FROM trip
  WHERE trip.days = hiking_trip.days
);

The above query compares city trips and hiking trips which last the same number of dates. It then returns all hiking trips which are cheaper than any city trip of the same duration.

Exercise

Select those trips which last shorter than any hiking_trip with the same price.

Stuck? Here's a hint!

Type:

SELECT *
FROM trip
WHERE days < ANY (
  SELECT days
  FROM hiking_trip
  WHERE trip.price = hiking_trip.price
);