Sorry sanjooz, but that query won't work. MySQL won't let you DELETE from a table that you reference in the same DELETE statement's sub-SELECT. You can use a VIEW to get around this, but the problem I'm running into is that the asker wants to keep the first row and get rid of the rest. My solution gets rid of all the duplicates except for the *last* entry.
Main Topics
Browse All Topics





by: sanjoozPosted on 2009-09-02 at 11:35:29ID: 25244106
do you have a primary key in this table? is it anything other than phone_number? If so, assuming id is your primary key, this might work
delete from table1 where id > (select id from table1 where phone number = '1234567890' order by id limit 1)