var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: Deleting from more than one table
I have two tables that are related:
I can delete the related when there are records in both tables with:
DELETE table1, table2 FROM table1, table2 WHERE table1.t1ID = 1 AND table1.t1ID = table2.t1ID;
However the problem when I use the above query and there are no records relating to table1 in table2 as it doesn't delete the record in table1.
I was advised to use a left join:
DELETE table1, table2 FROM table1 LEFT JOIN table2 ON table1.t1ID = 1 AND table1.t1ID = table2.t1ID;
But this deletes all the records in Table1!
Any suggestions will be much appreciated!
The ON clause should only be used to describe how rows match when joined. The WHERE clause should be used to "filter" the results to affect only the rows you want.
DELETE table1, table2
LEFT JOIN table2 ON table1.t1ID = table2.t1ID
WHERE table1.t1ID = 1;