Basically, I have three tables
workplaces with a field id (the one of which i want to delete the associated data), and a participantlist_id that identifies the participant list.
participantlist – just list_id and name
participantlist_links – with list_id and participant_id
the query that i’m trying to use is this:
DELETE FROM workplaces,
participantlist,
participantlist_links
WHERE workplaces.id = '8' AND
workplaces.participantlist_id = participantlist_links.list_id AND
workplaces.participantlist_id = participantlist.list_id
but i get:
MySQL said:
1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE workplaces.id=’8′ AND workplaces.participantlist_id = participant’ at line 3
any ideas?
SOLUTION:
DELETE t1, t2, t3
FROM workplaces AS t1
LEFT JOIN participantlist AS t2 ON t1.participantlist_id = t2.list_id
LEFT JOIN participantlist_links AS t3 ON t2.list_id = t3.list_id
WHERE t1.id = '8'
You can use JOIN to delete from multiple tables like this:
http://dev.mysql.com/doc/refman/5.5/en/delete.html