I have an index table with trips that people can order, and a table with prices for these trips.
Tables
Travel
[tripid] [city] [province] [country] [culture] [nature] [rating]
Prices
[tripid] [date] [duration] [price]
Problem
When a user searches, I want to show the lowest available price. I am using the following query
SELECT t.*,
(SELECT MIN(price) FROM prices WHERE tripid = t.tripid)
FROM trips t;
This works, however, slowly. 5 seconds for 4000 results. Is there a faster way to achieve this?
source
share