Регламентный поиск дублей
Есть необходимость тестировать БД на наличие дублей. Вот скрипт:
SELECT acc2.ID as deleteID, stud2.ID as deleteStudID FROM `accounts` as acc1
INNER JOIN `accounts` as acc2 ON acc1.ID = acc2.ID-1
INNER JOIN `students` as stud1 ON acc1.ID = stud1.AccountID
LEFT JOIN `students` as stud2 ON acc2.ID = stud2.AccountID
LEFT JOIN `record_books` ON stud2.ID = record_books.StudentID
WHERE acc1.LastName = acc2.LastName and acc1.FirstName = acc2.FirstName and record_books.ID IS NULL