Considera quanto segue.
DROP TABLE IF EXISTS apartment;
CREATE TABLE apartment
(apartment_id SERIAL PRIMARY KEY
,apartment_name varchar(255) NOT NULL
);
INSERT INTO apartment VALUES
(1, 'Apartment 1'),
(2, 'Apartment 2'),
(3, 'Apartment 3'),
(4, 'Apartment 4');
DROP TABLE IF EXISTS booking;
CREATE TABLE booking
(booking_id SERIAL PRIMARY KEY
,start_date DATE NOT NULL
,end_date DATE NOT NULL
,apartment_id INT NOT NULL
);
INSERT INTO booking VALUES
(1, '2018-07-18', '2018-07-20', 1),
(2, '2018-07-21', '2018-07-23', 1),
(3, '2018-07-18', '2018-07-20', 2);
SELECT a.*
FROM apartment a
LEFT
JOIN booking b
ON b.apartment_id = a.apartment_id
AND b.start_date <= '2018-07-23'
AND b.end_date > '2018-07-21'
WHERE b.booking_id IS NULL;
+--------------+----------------+
| apartment_id | apartment_name |
+--------------+----------------+
| 2 | Apartment 2 |
| 3 | Apartment 3 |
| 4 | Apartment 4 |
+--------------+----------------+
In pratica, a meno che non sia vincolato a una transazione, un SELECT come questo è abbastanza privo di significato, perché un altro utente può facilmente venire ed effettuare la prenotazione mentre stai ancora verificando la disponibilità.