Hello. Been working on this query for some time and I'm having trouble with a selector. I have a properties table and a dates tables. The dates table contains dates (in a DATE and TIMESTAMP format) that are NOT AVAILABLE for the property. The WHERE clause only selects properties that have entries. This is a problem because it should also select properties that have zero entries, because they are 100% available to rent.
Here is a basic query:
SELECT p.*, p.land_id AS landCode, p.id AS propertyId, d.*, COUNT(d.id) AS land
FROM `properties` AS p
LEFT JOIN `dates` AS d ON `p`.`id` = `d`.`land_id`
WHERE (`d`.`timestamp` BETWEEN '1283317200' AND '1285909199')
GROUP BY `p`.`id `
ORDER BY `land` ASC
This only returns 1 property (because it has half of September blacked out) and not the other 2 which do not have any dates in September blacked out. If I leave out the WHERE clause, then it will return all properties like I need, but then the date range is not restricted by the user's search.