I have 2 tables setup like this:
Items:
id (int)
name (varchar)
category (int)
last_update (timestamp)
Categories
id (int)
name (varchar)
tree_id (int)
I want to delete all the records from Items
, who's last_update
is NOT today, and who's corresponding categories.tree_id
is equal to 1. However, I don't want to delete anything from the Categories
table, just the Items
table. I tried this:
$query = "DELETE FROM items USING categories, items
WHERE items.category = categories.id
AND categories.tree_id = 1
AND items.last_update != '".date('Y-m-d')."'";
However this just seems to delete EVERY record who's tree_id
is 1. It should keep items with a tree_id
of 1, as long as their last_update
field is today
What am I missing?