DB have two columns ID and parent ID. St is like: S1(ID) and Null(Parent ID), S2 and S1, S3 and S1, S4 and S2, S5 and S4. S1 is parent of S2 and S3, S2 is parent of S4 and so on. This list is not in sequence while saving in DB. how to figure out that S1 needs to be saved first then S2 and S3?