0
Guys, I have a basic question but I’m having a huge difficulty in making an appointment.
I have a protocol system in which protocol data is recorded in a table called PROTOCOL and the updates of each protocol are in another table called SITUATION.
I have an APB that shows all protocols that are 7 days without movement, follow my query:
SELECT p.ID_PROTOCOLO, p.NUMERO, s.DATA_CADASTRO
FROM protocolo p
INNER JOIN situacao s ON s.ID_PROTOCOLO = p.ID_PROTOCOLO
where s.DATA_CADASTRO < DATE_ADD(CURDATE(), INTERVAL -7 day)
GROUP BY p.ID_PROTOCOLO
I need this INNER JOIN to bring the last (most current) SITUATION registration but it is always bringing the first registered (oldest).
I already tried to do a sub-visit and I tried to do a select inside INNER JOIN, and I did not succeed.
For those who have experience just seeing will already know the solution, but for me it is very difficult to solve this small problem. Thanks for your help.