I have a table that holds username, updated date, and status as below:
name | Updated_on | Status
akg 29-NOV-10 Active
akg 13-JAN-12 NonActive
akg 10-MAR-12 Active
ems 23-JUL-12 NonActive
ems 10-SEP-10 Active
tkp 10-SEP-10 NonActive
tkp 13-DEC-10 Active
tkp 02-JUL-12 NonActive
tkp 24-SEP-10 Active
aron 12-JAN-11 NonActive
aron 07-NOV-11 Active
aron 25-JUN-12 NonActive
In this table user status is updated every time we change the status (ie a username can have many entries as shown in the table.
I would like the second last updated record for each user. ie for the above table, the result should be:
name | Updated_on | Status
akg 13-JAN-12 NonActive
ems 10-SEP-10 Active
tkp 13-DEC-10 Active
aron 07-NOV-11 Active
I’m really confused as I want to get the record of each users in this.
Is there any query which can be used for this?
Thank you
You could try that, it’s a bit verbose but it works:
Sqlfiddle