Dear All,
I have 2 tables one tblAssociate and tblData. The link between them is one to many. My search will be based on date time range where if I find even one data in tblData between the set range then I want to show the tblAssociate data. So I have build this query but the problem it takes more then 20 seconds at time. Any idea how to improve this query?
SELECT tblLocationFrom.geoFenceName As locationFrom,
tblLocationTo.geoFenceName As locationTo,
tblAssociate.associateID,
CAST(DATE_ADD(tblAssociate.dateTimeStartJourney, INTERVAL '+08:00'
HOUR_MINUTE) AS CHAR) As dateTimeStartJourney,
CAST(DATE_ADD(tblAssociate.dateTimeEndJourney, INTERVAL '+08:00'
HOUR_MINUTE) AS CHAR) As dateTimeEndJourney,
tblAssociate.totalC,
tblAssociate.totalD,
tblAssociate.totalE,
tblAssociate.totalP,
tblAssociate.totalS,
tblAssociate.totalW
FROM tblAssociate
JOIN tblGeoFence AS tblLocationFrom
ON tblAssociate.locationFromID = tblLocationFrom.geoFenceID
JOIN tblGeoFence AS tblLocationTo
ON tblAssociate.locationToID = tblLocationTo.geoFenceID
JOIN tblData On tblAssociate.associateID=tblData .associateID
WHERE Date_Add(tblData .dateTimer, Interval '+08:00' hour_minute)
BETWEEN '2011-10-19 00:00:00' AND '2011-10-20 23:59:59'