mardi 4 août 2015

How to select the Most Recent or last record from MySQL table using SQL syntax

How can I select Most Recent or Last 100 records from MY SQl Query. I have 18 Millions of records in database. I want to select 100 most recent records by using "Timestamp" Query but it would take more than 2 minutes of time. Have any other way to find the latest records without Order By

     SELECT DISTINCT(dd.Timestamp), dd.Amplitude , pd.PatientId   FROM DeviceDetails dd   JOIN DeviceSession ds 
     ON ds.DeviceSessionID = dd.ByDevSessionId  
     JOIN PatientSession ps ON ps.PatientSessionId = ds.ByPatientSessionId   
     JOIN PatientDetails pd ON pd.PatientDetailsId = ps.ByPatientId   
     WHERE   pd.HospitalPatientId = 'Rorys Test Ward Test Bed 2 @ 2015-07-31 18:36:41'
     AND dd.Timestamp < '2015-08-04 11:53:08.962'       
     ORDER BY dd.Timestamp   
     Limit 100 

Aucun commentaire:

Enregistrer un commentaire