Hierarchical querying, an interesting way of retrieving data for analysis, transforming and reporting. In latest version of CRM, we can use fetchxml to query and retrieve hierarchical data.

The hierarchical data retrieval in fetchxml can be achieved using following filter condition operators
  • above
  • eq-or-above
  • under
  • eq-or-under
  • not-under
  • eq-owneduseroruserhierarchy
  • eq-useroruserhierarchyandteams
Prerequisite:
Make sure the specific relationship is hierarchy enabled.

Sample Scenario:
Find all child account hierarchy for the parent account.

Fetchxml:
In the below fetchxml the highlighted operator called under will fetch all the accounts that are under the given accounts hierarchy.



"account" >

"and" >
"accountid" operator="under" value="a9df53b3-e31c-e711-8108-5065f38af901" />




Try all the above filter operators and also refer below MSDN article for more info and do not forget to go through restrictions.

https://msdn.microsoft.com/en-in/library/dn817893.aspx

Happy learning!