I have two tables
------------------------ | Vehicles | ------------------------ + id + | name | + available_from_date + | available_from_time | + available_to_date + | available_to_time | ----------------------- ------------------------ | Reserved_Vehicles | ------------------------ + id + | vehicle_id | + reserved_from_date + | reserved_from_time | + reserved_to_date + | reserved_to_time | -----------------------
I want to query vehicles table such that I get only those vehicles which meet the availability date and time and also not already reserved for that time.
For example, I want to search vehicles which are available FROM date 2012-07-27 & time 10:00 TO date 2012-08-15 & time 14:00.
How to solve above problem with one query?
Thanks in advance. 🙂
It sounds like you could just use AND in your WHERE clause. Is that not working?
Do you need to query both tables? Or can you safely assume that if a car is reserved at a given time then it’s not available, and if it’s available then it’s not reserved?