3
I have the following table/fields:
Table: PLANS
ID(PK)VEICULO(IS REPEATED)DATAINCLUSAOREVISAO(UNIQUE)
I need to bring the number of REVISAO of each VEICULO of the latter DATAINCLUSAO.
So I can bring the VEICULO and the last DATAINCLUSAO, but I put myself REVISAO, will ask to add to GROUP BY, and I can’t, because REVISAO is unique, so it would bring me everything.
Place MAX(REVISAO) may bring me incorrect value.
SELECT VEICULO, MAX(DATAINCLUSAO)
FROM PLANOS
GROUP BY VEICULO
In short: what I need is to bring the value of REVISAO, concerning the last DATAINCLUSAO of each VEICULO.
Your answer is correct, but I didn’t pay attention and missed a crucial bit in the question: "The possibility of query without subquery!"... If it does not exist, I will accept the answer with subquery, as the question will serve as a search source. Thank you and forgive me the failure! ;)
– rbz
Without the subquery will not succeed, because it needs the last inclusion date of each vehicle, which automatically requires to have another consultation.
– João Martins
That’s where @Joãomartins spoke! + 1 in reply
– Melissa