In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `tb_DeviceLog` ADD INDEX `tb_devicelog_idx_inventorylogid_trackedon` (`inventoryLogId`,`trackedOn`);
ALTER TABLE `tb_InventoryLog` ADD INDEX `tb_inventorylog_idx_assignedtocustid` (`assignedToCustId`);
ALTER TABLE `tb_Logins` ADD INDEX `tb_logins_idx_username` (`userName`);
SELECT
DL.lat,
DL.lng,
DL.speed,
DL.trackedOn,
IL.speedLimit,
IL.deviceName,
IL.deviceId,
isnull(DeviceIcon,
'Content/images/beach-car.png') AS DeviceIcon
FROM
tb_DeviceLog DL
INNER JOIN
(
SELECT
tb_DeviceLog.inventoryLogId,
max(tb_DeviceLog.trackedOn) AS MaxDate
FROM
tb_DeviceLog
GROUP BY
tb_DeviceLog.inventoryLogId
ORDER BY
NULL
) IDL
ON DL.inventoryLogId = IDL.inventoryLogId
AND Dl.trackedOn = IDL.MaxDate
INNER JOIN
tb_InventoryLog IL
ON DL.inventorylogid = IL.id
INNER JOIN
tb_Logins LGN
ON LGN.customers_id = IL.assignedToCustId
WHERE
LGN.userName = 'cadmin'