Use anti semi join, under request return numbers, which are available for booking within the specified registration and check-out limits. This is in Rails.
Communication
Reservation belongs to Room
The room has a lot of booking
Inquiry
check_in_at = '2016-12-28'
check_out_at = '2016-12-29'
Room.where.not ("EXISTS (SELECT a reservation) * From bookings, where rooms.id = bookings.room_id AND bookings.check_in_at BETWEEN AND AND? And bookings.check_out_at BETWEEN? AND?)", Check_in_at, check_out_at, check_in_at, check_out_at )
source share