SELECT ; id; , !ISNULL((SELECT .T. FROM PivotConstant WHERE EXISTS(SELECT*FROM tree WHERE parentId=T.id))) hasChild; FROM tree T