1
I have three tables: -customers -plans -services
On the table services have servico_A, servico_B and servico_C that are related in the table plans.
I need to list all customers who do not have a service plan. Even if he has other plans with other services, he should not be listed.
SELECT
p.codcliente
FROM
planos p
LEFT JOIN servicos se ON p.codser = se.codser
LEFT JOIN clientes c ON p.codcliente = c.codcliente
WHERE
#ele nao tenha nenhum servico_C
ORDER BY p.codcliente
Just for a broader understanding: The sub-query returns an array with all values found, and the clause NOT EXISTS query if in these returned values it finds, in this case, the p.codclient?
– Rafael Silva
@Rafaelsilva added a more detailed explanation
– Sorack