select *
from users u
where u.Assignable = 1
and u.UserID not in (
select UserID
from Appointments a
join TimeSlots t on a.TimeSlotID = t.TimeSlotID
where t.EndTime > now()
and t.EndTime > @desiredStartTime
and t.StartTime < @desiredEndTime
)
rediger Tager et signal fra tandu
Jeg tror, at dette også ville fungere, og det har den ekstra ydeevnefordel, at der ikke er nogen underforespørgsler:
select *
from users u
left join Appointments a on a.UserID = u.UserID
left join TimeSlots t on (
a.TimeSlotID = t.TimeSlotID
and t.EndTime > now()
and t.EndTime > @desiredStartTime
and t.StartTime < @desiredEndTime
)
where
u.Assignable = 1
and t.TimeSlotID is null