List:General Discussion« Previous MessageNext Message »
From:Gerald Clark Date:March 16 2000 3:41pm
Subject:Re: DELETE all but one
View as plain text  
1. Select these records into a temporary table.
2. Add a unique index on these fields to the temporary table with ALTER IGNORE.

3. Delete these records from the origional table.
4. Insert tthe remaining record from the temporary table.

Oleg Timofeyev wrote:

> Oh no no no hehe that would get me in a lot of trouble see I am not trying
> to get rid of everyhitng but that. The actual situation is:
>
> There are 10 records in the database that have ID=5 and KEYWORD='money'
> So I want to remove only nine of them, see, to get rid of the duplicates and
> still want to have one and only one record with ID=5 and KEYWORD='money'
>
> Sorry for not explaining it properly before :) . Any ideas now? Thanks a lot
> for your time.
>
> Sincerely,
> Oleg Timofeyev
> 2xdigi.com
> (818)476-0076
> olegtim@stripped
>
> > The following should do the trick:
> >
> > DELETE from table1 where not (keyword = 'money' and id = 5);
> >
> > Make sure that the select with the same where clause selects only what
> needs to
> > be deleted before you actually delete :-), and make sure to have a
> backup - good
> > idea for when you are about to delete a lot of records.
> >
> > --
> > Sasha Pachev
>
> --
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
> posting. To request this thread, e-mail mysql-thread31116@stripped
>
> To unsubscribe, send a message to:
>     <mysql-unsubscribe-gerald_clark=suppliersystems.com@stripped>

Thread
DELETE all but oneOleg Timofeyev14 Mar
  • Re: DELETE all but onesasha14 Mar
  • Re: DELETE all but oneOleg Timofeyev14 Mar
  • Re: DELETE all but oneGerald Clark16 Mar
Re: DELETE all but oneRichard Ellerbrock14 Mar
  • Re: DELETE all but oneDavid Diaz i Torrico14 Mar