I'm trying to write an SQL script to find the next to last record added to a table. The table in question (it's a table that tracks status changes to records that are in another table) has one row for every status change that is made to a record that is in the other table. So, there is a one to many relationship between the two tables. Also, every row in the status change table is date and time stamped.
For the sake of simplicity, let's call the status change table "TBL_B" and its "parent" table we can call "TBL_A". The 2 tables are related to one another through a single column (TBL_A.PONUM and TBL_B.PONUM).
What I am looking for is not the most recent record that was added to TBL_B for every record that is in TBL_A, but the next most recent. For example, assume that TBL_B has 4 rows in it for a single row in TBL_A as follows:
Row 1 was added on 1/1/2018
Row 2 was added on 2/1/2018
Row 3 was added on 3/1/2018
Row 4 was added on 4/1/2018
I want my query to return only Row 3
This is for a SQL Server DB
Any ideas / assistance / guidance is much appreciated