I have a table with an XML column. The XML can contain an optional link element.
<Link ReasonCode="MultiLabel">
<UUID>1d177dee-1da4-4451-b175-396666afc370</UUID>
</Link>
I want to fetch all records from the table that do not have link element. From those records that have the link element, I want only the DISTINCT records fetched. If two records have the same link element, skip the second occurrence. The query that I tried,
SELECT DISTINCT cast((xpath('/Data/Link', xmldata)) AS TEXT)
FROM tblData AS link
WHERE link != '{}'
ERROR: input of anonymous composite types is not implemented
- What is it that I am doing wrong here that causes the above mentioned error? The query works fine without the
WHERE
clause. - In addition to this I want to use an order by clause before the
DISTINCT
method starts processing the results. Again, I messed up with the syntax of using order by and distinct together, and I got an error.
How do I achieve ordering of the results based on the value of a column in the table, for this query?