I have the following XML.
<Root>
<Child1>
<SubChild1>some value</PartNumber>
</Child1>
<Child2>some data</Child2>
<Child3>some data</Child3>
<Child4>some data</Child4>
<Child2>some data</Child2>
<Child3>some data</Child3>
<Child5>some data</Child5>
</Root>
I want to remove the duplicate nodes and return the XML in below format.
<Root>
<Child1>
<SubChild1>some value</PartNumber>
</Child1>
<Child2>some data</Child2>
<Child3>some data</Child3>
<Child4>some data</Child4>
<Child5>some data</Child5>
</Root>
I tried below SQL query but it did not work.
SELECT @myXMLData.query('
for $x in distinct-values(//*)[1]
return
(//*)[1]
')
I also tried distinct-values but it returns the values (without enclosing node attributes).
SELECT @XML.query('<Root>{ distinct-values(//*) }</Root>')
Any help with this please?