I want to avoid using DELETE items from the table, but select out the ones I need. The following code results in "time exceeded limitation" error. Can someone help me to optimize it?
SELECT Id, Email FROM Person WHERE Id IN ( SELECT MIN(Id) FROM Person GROUP BY Email );
In MySQL, you can't modify the same table which you use in the SELECT part.
Check this post in stackoverflow
But you can try adding one more select like following
delete from Person where Id not in ( select minId from (select min(Id) minId from Person group by Email) t )
I made same error, haha
broken link. here's the correct link