SELECT p.[ChildTaskId],
       p.[ParentTaskId],
       parent.[Status] AS [ParentStatus],
       parent.[RetryOfTaskId] AS [ParentRetryOfTaskId],
       parent.[ReplayedFromTaskId] AS [ParentReplayedFromTaskId]
FROM [dbo].[ParentTaskExecutions] p
    LEFT JOIN [dbo].[TaskExecutions] parent
ON parent.[Id] = p.[ParentTaskId]
WHERE p.[ChildTaskId] = @ChildTaskId
ORDER BY parent.[Priority] DESC, parent.[QueuedAt] DESC, p.[ParentTaskId];
