2
respostas

POR QUE ESTE DELETE COM SELECT NÃO FUNCIONA

Gostaria de entender o motivo de este delete não funcionar... Alguém consegue explicar?

delete from notas_fiscais
where NUMERO in
(select A.NUMERO from notas_fiscais A
inner join clientes B on A.CPF = B.CPF
where B.IDADE <= 18);

O erro apresentado é o seguinte:

You can't specify target table 'notas_fiscais' for update in FROM clause

2 respostas

Olá Lucas, tudo bem?

Segundo a documentação do MySQL, não é permitido excluir de uma tabela e selecionar a mesma tabela em uma subconsulta, por este motivo o erro é retornado no momento que você está tentando realizar o delete.

Espero ter ajudado e bons estudos!

Entendi Danielle,

Muito obrigado!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software