1
Hello friends, a question has arisen, where even entering several forums I did not succeed in Ana it, in this way see if they can give me a "light". I have a main SELECT, and some sub-queries. In one of these sub-queries I need to pass as parameter in the WHERE clause a column that is present in the main SELECT, something similar to what is below.
SELECT DISTINCT ID AS NUMERO_CONTRATO,
QUANTIDADE = (SELECT COUNT(PARCELA) FROM
CONTRATO_FINANCEIRO WHERE ID = NUMERO_CONTRATO)
FROM CONTRATO_FINANCEIRO
However after executing this query error is generated because there is no NUMERO_CONTRATO field, and if I pass the ID column itself it will not in turn with the value of the first query.
Already tried to use JOIN?
– Rogers Corrêa
Thought I will not need JOIN, to run the query it is enough only that the column (NUMERO_CONTRATO) that I pass as parameter in the WHERE clause of the sub-query is "accepted"
– Junior Ferreira Do Nascimento
@Juniorperreiradonascimento: It was missing to relate the subconsulta with the query. This is called correlated subconsulta. // Have you evaluated Rovann’s proposal? Seems to me the solution.
– José Diz