For each record, I'm trying to get all previous records from the last 20 days where Tail and ATA are same. This SQL works but if there's two records for the same Date, I get 4 records which I understand. I have another field [ExTime] but I don't know how to set the criteria to return records where t47Ex_1.ExTime is < t47Ex.ExTime only if the Dates are same.
SELECT t47Ex.ExID, t47Ex_1.ExID AS ExHistID, t47Ex_1.ExDate AS ExHistDate
FROM t47Ex LEFT JOIN t47Ex AS t47Ex_1 ON (t47Ex.Tail = t47Ex_1.Tail) AND (t47Ex.ATA = t47Ex_1.ATA)
WHERE (((t47Ex_1.ExID)<>[t47Ex]![ExID]) AND ((t47Ex_1.ExDate)>=[t47Ex]![ExDate]-20 And (t47Ex_1.ExDate)<=[t47Ex]![ExDate]) AND ((t47Ex.ExDate)>=#1/1/2006#))
ORDER BY t47Ex.ExID, t47Ex_1.ExID;
Thanks for any help!!
Mike
SELECT t47Ex.ExID, t47Ex_1.ExID AS ExHistID, t47Ex_1.ExDate AS ExHistDate
FROM t47Ex LEFT JOIN t47Ex AS t47Ex_1 ON (t47Ex.Tail = t47Ex_1.Tail) AND (t47Ex.ATA = t47Ex_1.ATA)
WHERE (((t47Ex_1.ExID)<>[t47Ex]![ExID]) AND ((t47Ex_1.ExDate)>=[t47Ex]![ExDate]-20 And (t47Ex_1.ExDate)<=[t47Ex]![ExDate]) AND ((t47Ex.ExDate)>=#1/1/2006#))
ORDER BY t47Ex.ExID, t47Ex_1.ExID;
Thanks for any help!!
Mike