Optimer query
SELECT DISTINCT u.user_id, CONCAT(fname, ' ', lname) AS full_nameFROM user AS u
LEFT JOIN participates AS p
ON
p.user_id = u.user_id
AND
status != 'STATUS_REJECTED'
LEFT JOIN appointment AS a
ON
p.appointment_id = a.appointment_id
AND
((a.start_time >= '$start_time' AND a.start_time < '$end_time') OR (a.end_time >= '$start_time' AND a.end_time < '$end_time') OR (a.start_time < '$start_time' AND a.end_time > '$end_time'))
AND
a.cancelled_time IS NULL
LEFT JOIN appointment AS ap
ON
ap.user_id = u.user_id
AND
((ap.start_time >= '$start_time' AND ap.start_time < '$end_time') OR (ap.end_time >= '$start_time' AND ap.end_time < '$end_time') OR (ap.start_time < '$start_time' AND ap.end_time > '$end_time'))
AND
ap.cancelled_time IS NULL
WHERE
a.appointment_id IS NULL AND ap.user_id IS NULL
----------------
Jeg har på fornemmelsen man kan slippe for den sidste LEFT JOIN (LEFT JOIN appointment AS ap).
Er der nogle der kan lure hvordan? Sådan at forspørgslen naturligvis gør det samme som nu.
