select * from apartment as a
LEFT JOIN (SELECT r.id, sum(r.guests) as guests FROM reservation AS r
GROUP BY r.apartment_id ) as r ON a.id = r.id
WHERE a.slots > r.guests
CREATE TABLE appartament ( id int, name varchar(20), slots int );
INSERT appartament VALUES ( 1, 'Redison', 3 ), ( 2, 'Qubus Hotel', 2 ), ( 3, 'Hotel Nuber One', 4 );
CREATE TABLE reservation ( appartament_id int, guests int );
INSERT reservation VALUES ( 1, 2 ), ( 1, 1 ), ( 3, 1 );
SELECT name, slots, IFNULL( SUM( guests ), 0 ) AS CountGuest
FROM reservation
RIGHT JOIN appartament ON id = appartament_id
GROUP BY name
HAVING CountGuest < slots