Hi,
the query below counts records where typeid = 1 and where a record with a typeid = 2 does not exist - but runs slow
can anyone see a way to improve this?
the query below counts records where typeid = 1 and where a record with a typeid = 2 does not exist - but runs slow
can anyone see a way to improve this?
Code:
SELECT event.eventid,
event.deptlinkid,
cus.custitle,
cus.firstname,
cus.surname,
TA.actiondate
FROM event
INNER JOIN cus ON cus.cusid = event.cusid
LEFT JOIN
(SELECT action.actiondate,
action.eventid
FROM action
WHERE action.typeid = '1'
AND action.eventid NOT IN
(SELECT action.eventid
FROM action
WHERE action.typeid = '2')
)AS TA ON event.eventid = TA.eventid
WHERE event.userid = '39'
AND month(TA.actiondate) = '1'
AND year(TA.actiondate) = '2010'
GROUP BY event.eventid
ORDER BY TA.actiondate DESC