Data for self-referencing foreign keys are indeed not sorted. When using the export function you can use the "Disable foreign key constraints" option instead. In the resulting export file they will be disabled before inserting the records and enabled again afterwards.