In this chapter, we can inspect the Multiple Table Deletes expression which is much like the use of Multiple Table Updates function.
More than one desk can be referred in WHERE clause of DELETE announcement in lots of DBMS dialects. For PG and MySQL, “DELETE USING” syntax is used; and for SQL Server, using “DELETE FROM” expression refers to more than one desk. The SQLAlchemy delete() construct helps each of these modes implicitly, by means of specifying more than one tables inside the WHERE clause as follows −
stmt = users.delete().\
where(users.c.id == addresses.c.id).\
where(addresses.c.email_address.startswith('xyz%'))
conn.execute(stmt)
On a PostgreSQL backend, the resulting SQL from the above declaration might render as −
DELETE FROM users USING addresses
WHERE users.id = addresses.id
AND (addresses.email_address LIKE %(email_address_1)s || '%%')
If this technique is used with a database that doesn’t aid this behaviour, the compiler will improve NotImplementedError.