past_bookings, even if there are some past_booked_services records whose partner_id is not the same as the value of the partnerId variable in my code.past_bookings to be only those records who had at least one past_booked_services joined record whose partner_id matches the value of partnerId. .range() as this is only a sample piece of code which is part of a more complex function so filtering from the application level is out of the question and needs to be applied from the database level.past_bookings and past_booked_services is a one-to-many relationship, therefore I cannot query the past_booked_services table first and then join it with past_bookings because this will result in many duplicate records of past_bookings.