The following query is not functioning properly.
I am attempting to look at two tables and wish to return all of the propertyID's that do not have a booking associated with the arrival and departure dates of a preexisting booking.
I feel like I should be using a JOIN of some sort (tried referencing this StackOverflow post) but I am not sure that's what I need to utilize ....
In researching I have been attempting to do it this way (this is not working accurately however). Can anyone recommend or share a better method of performing this query to get my desired result?
$btQuery = "
SELECT * FROM properties
WHERE pID NOT IN (
SELECT pID
from property_booking
WHERE pbDateArrive BETWEEN CAST('".$_GET['aaDate']."' AS DATE)
AND CAST('".$_GET['adDate']."' AS DATE)
OR pbDateDepart BETWEEN CAST('".$_GET['aaDate']."' AS DATE)
AND CAST('".$_GET['adDate']."' AS DATE))";
Greatly appreciate any assistance.
In reply to check the how GET params are being CAST: here is the echo back:
SELECT *
FROM properties
WHERE pID NOT IN (
SELECT pID
from property_booking
WHERE pbDateArrive BETWEEN CAST('2016-02-05' AS DATE)
AND CAST('2016-02-12' AS DATE)
OR pbDateDepart BETWEEN CAST('2016-02-05' AS DATE)
AND CAST('2016-02-12' AS DATE))