-5

Is it possible to delete between tables?

Something like...

delete from bd between table1 and table 10 where vehicle 761 

delete from bd.table_1 where id_vehicle=761
delete from bd.table_10 where id_vehicle=761
Paul Hunt
  • 3,395
  • 2
  • 24
  • 39
Sebas Bejenaru
  • 129
  • 1
  • 1
  • 10
  • 2
    A `DELETE` statement does only delete from one table. (With foreign keys, and triggers, you can have data deleted from several tables.) – jarlh Jan 27 '16 at 08:25
  • 1
    How is `between table1 and table 10` supposed to act? – Andrey Korneyev Jan 27 '16 at 08:25
  • Yes, I'm with andy, is it suppose to delete from table1 table2 table3...table10? – sagi Jan 27 '16 at 08:32
  • I'm doing this manually: delete from bd_veosat_posiciones.ruta_2016_01_26 where id_vehiculo=761; delete from bd_veosat_posiciones.ruta_2016_01_25 where id_vehiculo=761; delete from bd_veosat_posiciones.ruta_2016_01_24 where id_vehiculo=761; delete from bd_veosat_posiciones.ruta_2016_01_23 where id_vehiculo=761; I'm curious if exist a sentence to do this without a for or while to incremetent the day. – Sebas Bejenaru Jan 27 '16 at 14:52

1 Answers1

0

You can either write a stored procedure (look at mysql dynamic query in stored procedure) or change the table structure so that either the vehicle IDs are related via a foreign key constraint (then you can do cascading deletes, see http://www.mysqltutorial.org/mysql-on-delete-cascade), or use one big table to store everything, but partition it by date, if the content really reaches a size, where it makes sense.

Community
  • 1
  • 1
neurotic-d
  • 76
  • 1
  • 6