EXPLAIN SELECT ipCam.IpCam AS IpCam, ipCam.Name AS Name, Registration.ID AS ID, DATE_FORMAT( Registration.TsStart, '%d' ) AS TsD, DATE_FORMAT( Registration.TsStart, '%m' ) AS TsM, DATE_FORMAT( Registration.TsStart, '%y' ) AS TsY, DATE_FORMAT( Registration.TsStart, '%d/%m/%y %H:%i:%s' ) AS TsStart, DATE_FORMAT( Registration.TsStop, '%d/%m/%y %H:%i:%s' ) AS TsStop
FROM Registration, ipCam
WHERE ipCam.ID = Registration.IDCam
AND Registration.State =3
AND Registration.TsStart = (
SELECT MAX( TsStart )
FROM Registration max
WHERE State =3
AND max.IDCam = Registration.IDCam )
ORDER BY Registration.IDCam
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY ipCam ALL PRIMARY NULL NULL NULL 16 Using temporary; Using filesort
1 PRIMARY Registration ref IDCam IDCam 4 tvcc.ipCam.ID 105 Using where
2 DEPENDENT SUBQUERY max ref IDCam IDCam 4 tvcc.Registration.IDCam 105 Using where