I have a table user_status, which stores the status for each user, everytime a status changes, i apppend the status in the user_status table.
id status created
1 ACTIVE 08-10-2017 08:21:22
1 ACTIVE 08-10-2017 08:21:25
1 NON_ACTIVE 08-10-2017 08:22:23
2 NON_ACTIVE 08-10-2017 08:22:23
2 ACTIVE 08-11-2017 08:25:23
3 NON_ACTIVE 08-12-2017 08:23:23
What I am looking for is the last status for each user based on the created date so the output I am looking is
id status created
1 NON_ACTIVE 08-10-2017 08:22:23
2 ACTIVE 08-11-2017 08:25:23
3 NON_ACTIVE 08-12-2017 08:23:23
also once I do that, I am also interested to know if there is a way to get the second to last status (one before the last) status for each user
so output from this query i am looking ofr is
1 ACTIVE 08-10-2017 08:21:25
2 NON_ACTIVE 08-10-2017 08:22:23
3 NON_ACTIVE 08-12-2017 08:23:23
any suggestions, I