id | userid | deviceid | isactive | last_modified (timestamp) |
---|---|---|---|---|
1 | 12 | fdghfgh | true | 2021-02-12 |
2 | 12 | sdsdfg | true | 2021-02-14 |
3 | 5 | fghfgh | true | 2021-01-12 |
4 | 15 | dffdg | true | 2021-02-14 |
5 | 15 | dofghfjdog | true | 2021-01-09 |
Only one device should be active for a user. Above table user 12 and 15 having two active devices.
How to set the recently modified device as active and other devices as false (for the corresponding user) in postgresql query?
Result should be:
id | userid | deviceid | isactive | last_modified (timestamp) |
---|---|---|---|---|
1 | 12 | fdghfgh | false | 2021-02-12 |
2 | 12 | sdsdfg | true | 2021-02-14 |
3 | 5 | fghfgh | true | 2021-01-12 |
4 | 15 | dffdg | true | 2021-02-14 |
5 | 15 | dofghfjdog | false | 2021-01-09 |