Select to show clients that are not in another table

Asked

Viewed 50 times

0

What is the correct way to present my client table with the following clauses: Be more than 60 days without purchase, not in the Links table or have more than 20 days since the last call.

Fields table Client CNPJ, Client, Date Last Purchase

Campos Ligações CNPJ, Date Link.

1 answer

1


What is recommended on this site is you always show what you tried to do and if any error occurred or the obtained result was not as expected.

This is not a site to just ask them to do something for you. Usually such a question is simply rejected.

Since you’re new, I’ll show you but make a tour on how to use this site.

Try:

SELECT Clientes.* FROM Clientes INNER JOIN Ligações ON (Cliente.CNPJ = Ligações.CNPJ)
WHERE (Cliente.Data_ultima_compra < DATE_SUB(CURRENT_DATE, 60 DAY))
    OR (Ligações.CNPJ IS NULL)
    OR (Ligações.Data_ligação IS NOT NULL AND Ligações.Data_ligação < DATE_SUB(CURRENT_DATE, 20 DAY));
  • I only made the changes from Inner Join to Left Join, as the values shown will all be from the customer table. Thank you!

  • Correct, typing failure. No sense testing (CNPJ links IS NULL) on an INNER JOIN.

Browser other questions tagged

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