Verificar Join todos os clientes que não tem em uma tabela

Delphi

26/04/2005

Preciso vereficicar na tabela debitos todos
os clientes que não existem na tabela cliente, tentei assim + ainda
não deu certo, se alguem puder me pessar ou outro forma de fazer isso ?
Obrigado a tds !!
with Query1,sql do
begin
clear ;
Add(´SELECT DISTINCT( DEBITO.NOME_CLIENTE)´);
Add(´FROM DEBITO´);
Add(´INNER JOIN CLIENTES ON ( CLIENTES.NOME <> DEBITO.NOME_CLIENTE )´);
Active := True;
end;


Essistemas

Essistemas

Curtidas 0

Respostas

Kotho

Kotho

26/04/2005

Você pode usar a clausula NOT EXISTS:

SELECT DISTINCT DEBITO.NOME_CLIENTE
FROM DEBITO
WHERE NOT EXISTS (SELECT CLIENTES.NOME
  FROM CLIENTES
  WHERE CLIENTES.NOME = DEBITO.NOME_CLIENTE)


Ou se o bco que vc está utlizando não permitir sub-selects, faça um LEFT JOIN:

SELECT DISTINCT DEBITO.NOME_CLIENTE
FROM DEBITO
  LEFT JOIN CLIENTES ON (DEBITO.NOME_CLIENTE = CLIENTES.NOME)
WHERE CLIENTES.NOME IS NULL



GOSTEI 0
POSTAR