sql - Delete from multiple tables in one single query -
i beginner in db2. want delete 2 tables using 1 query. reason why want because condition delete complex , implies join
in big tables. don't want same query twice. want :
delete table1 t1, table2 t2 t1.id = t2.id , id in ( -- select , join stuff)
with db2 luw can using data change table reference:
with lst (id) ( -- select , join stuff), lst1 (id) ( select id old table ( delete table1 id in (select id lst) ) ) select id old table ( delete table2 id in (select id lst1) )
old table (delete ...)
data change table reference, contains in case rows have been deleted enclosed delete
.
i don't think trick supported on other db2 platforms, althought might in db2 z/os v.11 -- have no way of testing though.
Comments
Post a Comment