Why this SELECT statement won't work?

  • 0

    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
        (   SELECT MIN(Id) FROM Person
            GROUP BY Email

  • 4

    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

  • 0

    broken link. here's the correct link

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.