select distinct
fileID, parentID, batchID
from x where parentID is null
union
select
min(fileID), parentID, batchID
from x
where not parentID is null
group by parentID, batchID
The first part of the union gives us :
fileID parentID batchID
----------- ----------- -----------
1 NULL 1
2 NULL 1
3 NULL 1
4 NULL 1
5 NULL 1
and the second part ...
6 1 1
9 2 1
11 3 1