Delete query help!!!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shadowk
Forum Newbie
Posts: 2
Joined: Mon Jun 26, 2006 2:36 pm

Delete query help!!!

Post 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
User avatar
dyluck
Forum Commoner
Posts: 54
Joined: Thu Jun 26, 2008 1:44 pm

Re: Delete query help!!!

Post by dyluck »

is this query in sql itself or through php?
shadowk
Forum Newbie
Posts: 2
Joined: Mon Jun 26, 2006 2:36 pm

Re: Delete query help!!!

Post by shadowk »

I want to do it with mysql.

Thanks
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: Delete query help!!!

Post 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.
Post Reply