Why can't this work


  • 0
    S

    delete from person where id not in
    (select min(Id) from Person
    group by Email) ;

    It worked in Oracle


  • 0
    R

    It is mysql's restriction,can't delete data just from a query that selected from the same table straight. Cover a select like below can solve it.Besides an alias is required.

    delete from Person where Id not in (
        select a.Id from 
           (select min(Id) as Id from Person group by Email) a
    )

Log in to reply
 

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