0
The problem is this, I have the tables protocolo
and historico
; second stores several records linked to a record of the protocol table. I wanted to fetch the last record of each historical for protocol, but along with the rest of the fields in the historical, for example
SELECT MAX(id_historico), id_local, id_situacao, id_protocolo
FROM historico
GROUP BY id_protocolo
The problem is that when I do this query it returns the id_histotico
the maximum correctly, but the rest of the fields are not from the same line as the id_historico
, is returning other wrong fields. Could someone help me understand and resolve this?
Thanks for the answer, I currently use this method that you mentioned, but it is a bit heavy and the more data in the table the heavier it gets. I’m looking for a more efficient alternative, so I don’t need to compare the historical id_with all the data in the table through the IN ().
– Josué Pereira
basically I’m trying to avoid sub select
– Josué Pereira