Introduction
Very simple subqueries
Subqueries with multiple results
Correlated subqueries
19. The ANY operator in correlated subqueries
Other subqueries

Instruction

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

SELECT
  *
FROM HikingTrip
WHERE HikingTrip.Price < ANY (
  SELECT
    Trip.Price
  FROM Trip
  WHERE Trip.Days = HikingTrip.Days
);

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

Exercise

Select those trips that are shorter in duration than any HikingTrip with the same price.

Stuck? Here's a hint!

Type:

SELECT
  *
FROM Trip
WHERE Trip.Days < ANY (
  SELECT
    HikingTrip.Days
  FROM HikingTrip
  WHERE Trip.Price = HikingTrip.Price
);