0

I have a database with many tables, I simply want to delete all rows from any table that have a field of 'id_shop' with a value of '2' how can I do this with MySQL, without listing all of the table names in the query?

Thanks

user1280853
  • 1,079
  • 5
  • 14
  • 23
  • This has already been answered. http://stackoverflow.com/questions/3331992/how-to-delete-from-multiple-tables-in-mysql Basically, don't. – Heath N May 22 '14 at 16:03
  • I'd add... there are good reasons for this. If you have defined CASCADE DELETEs then the RDBMS would know how to do it, and could do it for you when you delete the shop. But without that, you cannot just delete from a bunch of tables. You might have foreign keys and dependencies amongst the tables. You need to figure out the correct order in which to execute the delete. If it happens often, write a script or a stored procedure, so you can reuse it ;) – Frazz May 22 '14 at 16:43

1 Answers1

0

This will work:

Delete a,b,c From tb1 a
Inner join tb2 b
On (a.id=b.id)
Inner join tb3 c
On (b.id=c.id)
MelgoV
  • 661
  • 8
  • 21