Hi all,
For a client I have built a travelagency website. Now they asked me to optimize and automize some things. One of these things is that the accommodations shown in the searchlist must be bookable.
Simplified this is the structure
I have an AccommodationObject, an Accommodation has 1 or more PricePeriods.
What I need to do pick out the last priceperiod connected to a given accommodation. The priceperiod has a field 'date_until', which is a timestamp. In the query a check must be made, current timestamp must be less than the last timestamp from a priceperiod.
This is easy to do with a second query which just gets the last timestamp from the priceperiod table from all the priceperiod-rows connected to the given accommodation.
I'm wondering if this is the best case, or if I should use a subquery for this. And if so, how would a query like this look? I don't have much experience with subqueries.
Hope to hear from you!
Thanks in advance for the effort you take to write an answer!
Ben Fransen
Update
Table structure (simple)
Accommodation ->ID
PricePeriod -> ID | AccommodationID | DateUntil
Simplified:
SELECT fieldlist FROM Accommodation WHERE ID = $id
SELECT MAX(DateUntil) FROM PricePeriod WHERE AccommodationID = $id
But I would like to this in one query. I hope it's clear this way..