Sort the select query by entryorguid AND id so proper output is shown. Thanks to @Malcrom for the notice