Ты этим запросом по каждому email находишь last login. Если правильно понял, должно быть просто что-то вроде update auth_user set email ='' where last_login <> (select max(last_login) from auth_user)
update au set email = '' from auth_user au join ( select email, max(last_login) as max_login from auth_user group by email HAVING count(email) > 1 and email!='' ) x on au.email = x.email and au.last_login<>x.max_login
Попробуй такой вариант. Находим все id с максимальной датой и апдейтим все, кроме них update au set email = '' from auth_user au where au.id not in ( select a1.id from auth_user a1 inner join ( select max(last_login) as last_login, email FROM auth_user group by email) a2 on a2.email = a1.email and a1.last_login = a2.last_login)
select * from auth_user au right join (select distinct max(last_login) as Max_lof, email from auth_user group by email HAVING count(email) > 1 and email!='' ) ss on au.email = ss.email and au.last_login <>ss.Max_lof