• I would think the old, trusty MAX() would be clearer and less overhead than the mirrored function:

    DELETE FROM tn

    FROM dbo.tablename tn

    INNER JOIN (

    SELECT location, MAX(bookid) AS bookid

    FROM dbo.tablename

    GROUP BY location

    ) AS tn_max ON

    tn.location = tn_max.location AND

    tn.bookid < tn_max.bookid

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.