in reply to sort sequences and keep ID of them

What does your data look like and what do you expect the result to look like? maybe you can provide a runnable sample with the minimum data required to demonstrate the problem included in the sample code? I know what I mean. Why don't you? may help you understand what we would like to see.

True laziness is hard work