Question

I am trying to remove a few rows in some of my tables according to an ID from another table (items, purchasedBy).

Here's what I am trying to do..

DELETE from items.sql where 'PurchasedBy' is 84. DELETE from items_people where item_id is (item_id inside items.sql from the top query) DELETE from items_places where item_id is (item_id inside items.sql from the top query)

so if that makes any sense... here is a sum of what I am trying.. items.sql contains the rows "item_id" and "purchasedBy". items_people and items_places.sql need to have rows deleted according the item_id where the purchasedby is 84..

I really hope this makes sense cause my head is hurting from just thinking of how to explain it... sorry!

Was it helpful?

Solution

MySQL supports multi-table DELETE syntax.

DELETE i.*, p.*, pl.*
FROM items AS i
LEFT OUTER JOIN items_people AS p USING (item_id)
LEFT OUTER JOIN items_places AS pl USING (item_id)
WHERE i.PurchasedBy = 84;

OTHER TIPS

If you are just looking for the correct syntax then you can use:

DELETE FROM {table} WHERE {param} = 84

Replace {table} with your table name and replace {param} with your column where you expect the ID to match ie item_id or purchasedBy.

I can't give better advice at the moment as I don't really understand your table structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top