The idea behind this is to add a sequence number to the records and then take the Top 1 rank and Bottom 1 Rank from the records.