With this query i will find all apartments that are available.
All the available apartments have no booking id.
What i want: When it has a booking id and the status is cancelled I also want the apartment to show up, but i don’t know how to…
SELECT a.id, a.num_persons, a.rating, a.lat, a.lng, a.street, a.number
,c.title, c.introduction, c.text, c.area, c.long_term_rental, c.beds
, c.features ,c.services_and_equipment, c.terms_and_conditions
, m.url
FROM appartments AS a
INNER JOIN appartments_content AS c on c.parent_id = a.id
INNER JOIN meta AS m on m.id = c.meta_id
LEFT JOIN appartments_bookings AS b
ON (b.appartment_id = a.id
AND NOT ((? > b.departure) OR (? < b.arrival)))
-- this ? = arrival that ? = departure
WHERE b.id IS NULL
AND c.language = ?
AND a.hidden = ?
AND a.publish_on <= ?
AND a.city_id = ?
AND a.num_persons >= ?
ORDER BY a.num_persons ASC, a.publish_on DESC
LIMIT ? OFFSET ?'
I added this:
AND b.status != ? OR NOT ((? >= b.departure) OR (? < b.arrival))) WHERE b.order_id IS NULL
But this doesn’t work, i get nog results.
Don’t know mySQL syntax but change your WHERE to clause to something like…
WHERE (b.id IS NULL OR (b.id IS NOT NULL AND b.status = ‘cancelled’))
AND c.language = etc etc