SQL Delete with Join, Union in Firebird

Asked

Viewed 768 times

1

What would an Example of SQL Delete look like with Join or Union? I saw here in stackoverflow how to do in Mysql in sql Server more in Firebird I did not find or found in other forums. my SQL looked like this

DELETE FROM ANDAMENTOS_PROCESSUAIS
WHERE CODIGO_ANDAMENTO in(
  SELECT
    T2.CODIGO_ANDAMENTO
  FROM ANDAMENTOS_PROCESSUAIS T2
    LEFT JOIN PROCESSOS T3 ON T2.NUMERO_PROCESSO = T3.NUMERO_PROCESSO
  WHERE
    (T2.NUMERO_PROCESSO_AUX = T3.NUMERO_PROCESSO)  AND (T3.FASE_PROCESSO LIKE 'ARQUIVADO')    
  UNION ALL
  SELECT
    T2.CODIGO_ANDAMENTO
  FROM ANDAMENTOS_PROCESSUAIS T2
    LEFT JOIN PROCESSOS T3 ON T2.NUMERO_PROCESSO = T3.NUMERO_PROCESSO
  WHERE
    (T2.NUMERO_PROCESSO_AUX = T3.NUMERO_PROCESSO2)  AND (T3.FASE_PROCESSO2 LIKE 'ARQUIVADO'))
  • Is, is something missing in sql? Sort pass table in delete type ANDAMENTOS_PROCESSUAIS FROM ANDAMENTOS_PROCESSUAIS...

1 answer

1


You have to use the EXISTS.

Check in the official manual: Firebird DELETE

DELETE FROM employee e
WHERE NOT EXISTS(
  SELECT *
  FROM employee_project ep
  WHERE e.emp_no = ep.emp_no);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.