Order SQL results where each record referencing another record on the same table comes after the referenced record
问题 I have the following data: id, parent_id 1, 3 2, null 3, 2 4, 2 Where parent_id is a reference to the SAME table. I need to sort these columns so that each record is after its parent (not necessarily immediately after). So I would expect this result: id, parent_id 2, null 3, 2 1, 3 4, 2 I'm guessing there is no clean efficient way to do this without any significant schema changes, but in case anybody can think of a method I'm asking this here. One possible method would be to do multiple