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
Delete query help!!!
Moderator: General Moderators
Re: Delete query help!!!
is this query in sql itself or through php?
Re: Delete query help!!!
I want to do it with mysql.
Thanks
Thanks
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Delete query help!!!
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.
[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.