I have a item table, a tags table and a item_tagged table.
I want to remove rows from the the database if an item is not found in an array.
For example:
$array = 'john', 'game', 'nintendo';
Item id 2 has the following tags in the database:
'john', 'game', 'wonderful'
So ‘wonderful’ should be removed from the database.
What would be the sql for this?
item: id, content
item_tagged: item_id, tag_id
tag: id, name
Assuming you want to keep only the tags in the array, this should do the job.
Keep in mind this will not delete any orphaned tags, eg tags which are not assigned to any item.