DECLARE @NoEntity Integer DECLARE @Fic_Date DateTime DECLARE @Fic_Date2 DateTime DECLARE @First_Date DateTime SET @NoEntity=3 SET @Fic_Date='2009-11-14 14:48:17' SET @Fic_Date2='2009-11-15 14:48:17' SET @First_Date='1899-12-30 00:00:00' SELECT MAX(MitTelLogDet.Fic_Date) AS Last_Updated,MitTelLog.AI FROM MitTelLog (NOLOCK) INNER JOIN MitTelLogDet ON MitTelLog.AI=MitTelLogDet.MitTel_AI WHERE MitTelLog.NoEntity=@NoEntity AND MitTelLogDet.Fic_Date>=@Fic_Date AND MitTelLogDet.Fic_Date<=@Fic_Date2 AND MitTelLog.First_Date>@First_Date GROUP BY MitTelLog.AIFor some kind of reason, this doesn't seem to be optimized. Please, take in consideration that we have about two millions records in the main table and several millions in the child table. I need something that will work in just a few seconds as oppose to a minute.