-------------- DELETE AHR FROM app_highest_record AHR JOIN ( SELECT AppHighestRecordID FROM ( SELECT AppHighestRecordID, ROW_NUMBER() OVER ( PARTITION BY MaestroID, PlayerID, AppID ORDER BY CASE WHEN AppID = 105 THEN HighestRecord ELSE -HighestRecord END, AppHighestRecordID DESC ) AS rn FROM app_highest_record ) ranked WHERE rn > 1 ) dup ON dup.AppHighestRecordID = AHR.AppHighestRecordID -------------- Query OK, 8795 rows affected (0.942 sec) -------------- SELECT 'app_highest_record' AS table_name, COUNT(*) AS total_rows, COUNT(DISTINCT MaestroID, PlayerID, AppID) AS unique_combos FROM app_highest_record -------------- +--------------------+------------+---------------+ | table_name | total_rows | unique_combos | +--------------------+------------+---------------+ | app_highest_record | 220648 | 220648 | +--------------------+------------+---------------+ 1 row in set (0.190 sec) -------------- SELECT 'typing_exam_highest_record' AS table_name, COUNT(*) AS total_rows, COUNT(DISTINCT MaestroID, PlayerID, WritingID) AS unique_combos FROM typing_exam_highest_record -------------- +----------------------------+------------+---------------+ | table_name | total_rows | unique_combos | +----------------------------+------------+---------------+ | typing_exam_highest_record | 20413 | 20413 | +----------------------------+------------+---------------+ 1 row in set (0.024 sec) Bye