Return last entry of each object in the database

0

I have two tables:

               monitor_carro
id serial | setor_id |  modelo | ano | placa


               monitor_evento
id serial | lat | long | data | fkfuncionario_id | time | carro 

The monitor_evento table only has a foreign key that is official and in both tables the primary key is the serial id .

Assuming I have several cars inserted in the monitor_carro table and have several entries of these cars in my bd. I would like an help to return the last entry of each car in the monitor_evento table.

Could anyone help me with this?

Thank you in advance.

    
asked by anonymous 25.02.2015 / 19:24

1 answer

0
select distinct on (carro) *
from monitor_evento
order by carro, id_serial desc
    
26.02.2015 / 12:10