I have a postgresql database with a table like this:
id_usuario | dt_atualizacao | atualizacao | outros_dados
123 | 01-01-2001 | 0 | abc
123 | 01-01-2005 | 1 | abe
123 | 01-01-2012 | 1 | acd
123 | 01-01-2018 | 1 | acc
124 | 01-01-2017 | 0 | acj
124 | 01-01-2018 | 1 | agy
125 | 01-01-2018 | 0 | awe
What happens is this: In this application, when a user is registered for the first time, he leaves the field atualizacao = 0
and sets the current date.
But when an update is made to this register (say I changed the field outros_dados
), instead of updating the current record, it creates a new record with a new date and field atualização = 1
.
What I need is a select that takes all user ids, without repeating it and being the most current one. In the example above, I would need the following result:
id_usuario | dt_atualizacao | atualizacao | outros_dados
123 | 01-01-2018 | 1 | acc
124 | 01-01-2018 | 1 | agy
125 | 01-01-2018 | 0 | awe
Any tips on how to do this?