Your request should be reorganized, as well as smooth tables
Here is your original request:
SELECT AlertTypeID FROM incidentalert INNER JOIN incidentalerttype ON incidentalert.alerttypeid=incidentalerttype.AlertTypeID WHERE IncidentID=111210;
Since you are going to use only one incident identifier trying to extract it before the JOIN happens:
SELECT ia.AlertTypeID FROM (SELECT AlertTypeID FROM incidentalert WHERE IncidentID=111210) ia INNER JOIN (SELECT AlertTypeID FROM incidentalerttype) iat USING (AlertTypeID) ;
This should happen much faster as the number of incidents grows.
IF you need all the columns from a row in a random row, change it as follows:
SELECT ia.* FROM (SELECT * FROM incidentalert WHERE IncidentID=111210) ia INNER JOIN (SELECT AlertTypeID FROM incidentalerttype) iat USING (AlertTypeID) ;
Give it a try !!!
source share