Page 1 of 1

Delete query help!!!

Posted: Thu Jun 26, 2008 5:22 pm
by shadowk
Hello,
I have 2 tables( product, product_attribute), and product_attribute table has product_id field. I want to delete all attributes have product_id that not exist in product table. I tried NOT EXIST and NOT IN but i keep getting errors. I need help.

Thanks

Re: Delete query help!!!

Posted: Thu Jun 26, 2008 5:23 pm
by dyluck
is this query in sql itself or through php?

Re: Delete query help!!!

Posted: Thu Jun 26, 2008 5:44 pm
by shadowk
I want to do it with mysql.

Thanks

Re: Delete query help!!!

Posted: Thu Jun 26, 2008 9:23 pm
by Ollie Saunders
This took some lengthy research. But it's ok because I badly need to brush up on my MySQL.
[sql]DELETE `b` FROM `b` LEFT JOIN `a` ON `a`.`id` = `b`.`a_id` WHERE `a`.`id` IS NULL[/sql]
I guess you can figure out how to change the columns names etc.