in reply to sort based on last and first value

Where is the actual problem you have?