como melhorar esta query ?

Delphi

29/08/2006

tenho duas tabelas: ENTRADA e PROCESSADOS,
preciso de todos os registros que existam na tabela: ENTRADA e não exintam na tabela: PROCESSADOS.

atualmente estou fazendo assim:
select * from ENTRADA E
where E.BANCO not in (select P.BANCO from PROCESSADOS P) or
          E.AGENCIA not in (select P.AGENCIA from PROCESSADOS P) or         
          E.CONTA not in (select P.CONTA from PROCESSADOS P) or           
          E.CHEQUE not in (select P.CHEQUE from PROCESSADOS P) or          
          E.VALOR not in (select P.VALOR from PROCESSADOS P)


assim até funciona com tabelas de poucos registros, mais quando as tabelas são grandes(o que acontece em 70¬ dos casos) demora muito.

preciso de uma ajuda porque sei que uma consulta em duas tabelas grandes usando muitos subSelects não é muito aconselhavel e não consegui encontrar uma outra alternativa.

desde já agradeço !!!


Fabiano Góes

Fabiano Góes

Curtidas 0

Respostas

Motta

Motta

29/08/2006

tente com outter join, em geral é mais rápido

exemplo

 
SELECT *
FROM    USUARIO , POST
WHERE  USUARIO.CODUSU = POST.COD_USU (+)
AND      POST.COD_USU IS NULL


(+) INDICA OUTTER JOIN NO ORACLE - FAÇA A ADAPTAÇÃO SE NECESSÁRIO


GOSTEI 0
Night_man

Night_man

29/08/2006

tenta assim

Select *
From ENTRADA
Where
Not Exists (Select 1
From PROCESSADOS
Where PROCESSADOS.BANCO = ENTRADA.BANCO And
PROCESSADOS.AGENCIA = ENTRADA.AGENCIA And
PROCESSADOS.CONTA = ENTRADA.CONTA And
PROCESSADOS.CHEQUE = ENTRADA.CHEQUE And
PROCESSADOS.VALOR = ENTRADA.VALOR)


GOSTEI 0
POSTAR