SELECT TOP (500) ID, Personname, Personcode, Telphone, Fraction
into temp3
FROM Records AS a
WHERE (LEN(Personcode) = 18 OR
LEN(Personcode) = 15) AND (NOT EXISTS
(SELECT 1 AS Expr1
FROM Records
WHERE (Personname = a.Personname) AND (Fraction > a.Fraction) OR
(Personname = a.Personname) AND (Fraction = a.Fraction) AND (ID < a.ID)))
ORDER BY Fraction DESC