0
I’m implementing the report module in a system I’m developing, but I can’t get where I want, my scenario:
I have an equipment table, linked by foreign key to another table called maintenance, in the maintenance table I register only the date of maintenance and connect to the desired equipment
When I try to return one query for the report, if there are two maintenance dates, it returns two Rows of the same equipment, changing only the date of maintenance...
I wanted to return only the date of ULTIMA maintenance, but I’m not getting.
I am using the following query:
SELECT * FROM equipamento
INNER JOIN manutencao ON id_equipamento = id_equipamento_manutencao
Print how you are returning in the report:
I understand "last" as the latest date, use the GROUP BY clause and the MAX aggregation function:
SELECT equipamento.id_equipamento, max(manutencao.data) FROM equipamento 
INNER JOIN manutencao ON id_equipamento = id_equipamento_manutencao
GROUP BY equipamento.id_equipamento
.– anonimo
Anyway, you should search here on the site, because this question has already been made in some different ways. If none serves, you can [Dit] with a [mcve] (structure - only of the relevant fields - example data, intended result and result obtained with this data) It is worth reading the Stack Overflow Survival Guide in English to better understand the site and how to formulate it. Taking the opportunity to exchange the image for text - I’m trying to locate similar problem to indicate link.
– Bacco
About the "You close the question at the speed of light, to hinder you are quick, to help you run away." @Matheus' answer is a good example of why we close while details are missing. Came out a lot of complication (and does not solve duplicity, ie is not help) so far. We are helping the author and the community to ensure quality, which is the goal of the site. Read the Guide indicated in the previous comment to better understand.
– Bacco
Luis, I think this might help, it’s a similar case (different symptom, but same solution) and an explanation https://answall.com/questions/422495/
– Bacco
Thank you all very much for the answer, I managed to solve my problem !
– Luis Henrique De Almeida Santo