mysql - How do I efficiently delete all rows in a many-to-many relationship table that have a given destination exclusively on one side of the relationship? -



mysql - How do I efficiently delete all rows in a many-to-many relationship table that have a given destination exclusively on one side of the relationship? -

i have mysql database relationship table can simplified to:

create table `paths` ( `origin` char(32) not null, `destination` char(32) not null, `id` int(11) not null auto_increment, primary key (`id`), )

this many-to-many relationship. want delete paths paths origin lead place, e.g. neverland.

this sql should work:

delete paths origin in (select distinct origin paths destination = 'neverland') , origin not in (select distinct origin paths destination <> 'neverland');

but, there better, more efficient way?

thanks!

try:

delete paths paths p not exists (select * paths origin = p.origin , destination <> 'neverland')

mysql sql many-to-many query-optimization relationship

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -