I'm doing CONVERT_TZ twice in this query and it's horribly inefficient.
Any suggestions for improveing the query will be good.
I know you can set a variable but can you do it in the middle of a query and then reuse it?
Ideally I'd like to eliminate the HAVING too or at least some of it, cuz it's postprocessing
SELECT DISTINCT e.id,name,CONVERT_TZ(startTimestamp,u.sqlTimezone, '" .
$this->sqlTimeZone ."') as startTime, timeslots.ord, owner,
DATEDIFF(CONVERT_TZ(startTimestamp,u.sqlTimezone, '" .
$this->sqlTimeZone ."'), CURDATE()) as ddiff, rsvp as eventcolor,
slotbegin,slotend
FROM events e,invites i LEFT JOIN rsvps r ON
(r.event_id=i.event_id AND r.user = i.user_id ), users u, timeslots
WHERE e.id = i.event_id
AND i.user_id = " . $this->id . "
AND u.id = e.owner
AND timeslots.slottype = 3
HAVING TIME(startTime) BETWEEN timeslots.slotbegin AND timeslots.slotend
AND startTime BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 4 DAY)
ORDER BY startTime