Multiple Delete Syntax
Posted: Thu Aug 20, 2009 11:52 am
Hi all,
I've never had trouble deleting from multiple tables in the same query before...but this one is giving me grief.
Basically, for my forum, when a thread is deleted, I wish to delete all relating data from the subscriptions table, and the thread tracking table. For neatness' sake, I've been trying to do this in one query...
Here is a simplified representation of the two individual queries:
[sql]DELETE FROM `Thread_Tracking_Table` WHERE `Tracking_ID`='$id';[/sql]
[sql]DELETE FROM `Thread_Subscriptions_Table` WHERE `Subscription_ID`='$id';[/sql]
And this is my attempt at a single query, which only deletes the corresponding rows from the `Thread_Subscriptions_Table`, but doesn't delete anything from the tracking table:
[sql]DELETE S, D FROM `Thread_Subscriptions_Table` S, `Thread_Tracking_Table` D WHERE S.`Subscription_ID`='$id' AND D.`Tracking_ID`='$id';[/sql]
Any help would be awesome.
Thanks,
Jack.
I've never had trouble deleting from multiple tables in the same query before...but this one is giving me grief.
Basically, for my forum, when a thread is deleted, I wish to delete all relating data from the subscriptions table, and the thread tracking table. For neatness' sake, I've been trying to do this in one query...
Here is a simplified representation of the two individual queries:
[sql]DELETE FROM `Thread_Tracking_Table` WHERE `Tracking_ID`='$id';[/sql]
[sql]DELETE FROM `Thread_Subscriptions_Table` WHERE `Subscription_ID`='$id';[/sql]
And this is my attempt at a single query, which only deletes the corresponding rows from the `Thread_Subscriptions_Table`, but doesn't delete anything from the tracking table:
[sql]DELETE S, D FROM `Thread_Subscriptions_Table` S, `Thread_Tracking_Table` D WHERE S.`Subscription_ID`='$id' AND D.`Tracking_ID`='$id';[/sql]
Any help would be awesome.
Thanks,
Jack.