3
Model of the structure of the tables:
Tabela: Produtos
id_produto
titulo_produto
descricao_produto
Tabela: Fotos
id_foto
descricao_foto
id_produto
We can observe that the tables have in common the id_product field. Based on this information we will assemble our script.
The command below simplifies the form of data deletion, rather than using separate Deletes.
DELETE FROM tabela1, tabela2, tabela3
USING tabela1
INNER JOIN tabela2 INNER JOIN tabela3
WHERE tabela1.id = tabela2.id
AND tabela2.id = tabela3.id
AND tabela1.id = '$id'"
Good so far everything ok, but how to solve this when we don’t have the id_product field in common?
Example:
Tabela: Produtos
id
titulo_produto
descricao_produto
Tabela: Fotos
id_foto
descricao_foto
id_produto
Interesting, I’ll follow... But what would be the need for this? Opening a transaction and commiting would also suit you or not?
– Daniel Mendes
Yes, but that’s a doubt I have for knowledge purposes only
– Hugo Borges
See "Multiple-Table Syntax" in the manual https://dev.mysql.com/doc/refman/8.0/en/delete.html.
– anonimo