I am making a query using NOT EXISTS in a college job. The situation is as follows:
1.14 - Design the CPF and the amount payable in rents for customers who have rented media and have not yet made any payment.
The query performed and that worked, follows below:
SELECT A.CPF_Cliente,
SUM(ValorPagar) AS TotalValorPagar
FROM Aluguel A
WHERE NOT EXISTS (SELECT 1
FROM Pagamentos B
WHERE A.CPF_Cliente = B.CPF_Cliente
AND A.ID_Midia = B.ID_Midia
AND A.DataLocacao = B.DataLocacao)
GROUP BY A.CPF_Cliente;
Searching on how to use NOT EXISTS
, I noticed that in many examples they used SELECT 1
. I would like to know how it works and where I should use it.