Return last entry of each object in the database

Asked

Viewed 336 times

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_event table has only one foreign key that is working and in both tables the primary key is the serial id.

Suppose I have several cars inserted in the monitor_car table and I have several entries of these cars in my comic book. I would like a help to return the last entry of each car in the table monitor_event.

Could someone help me with this?

Thanks in advance.

  • Want to return the last selected record?

  • I’m working with Google maps. The entrances of the cars are nothing more than markers that I put on the map through a JSON using their latitude and longitude, but at the time of filtering them I’m not able to catch the last car face position on the seat.

1 answer

0


select distinct on (carro) *
from monitor_evento
order by carro, id_serial desc
  • It worked friend, I did not imagine the simplest. Thank you very much!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.