Hi @ and @,
First of all, many thanks for taking your time to answer my question, I appreciate it!
You both mention that cross-table column comparisons in FetchXML isn’t supported in Dynamics 365 On-Prem 9.1. Is there any official documentation where I can read about this? Or where have you gotten this information from?
Anyhow, the official example of a cross table join that I posted in my initial question is quite simple, it's a question that retrieves all contacts where there is an account with the same name as the fullname on the contact. That query can be re-written to just do an inner join on the account name and contact fullname column instead, which is supported in Dynamics 365 On-Prem 9.1.
In my case, what I really wanted to do was to check if there where any accounts with a related contact where the organization number (custom field) didn't match the social security number (custom field) on the contact record. And I wanted to do this in combination with some other checks. All this would be possible to do in a single query if I could use the cross-table comparison and it would only return me the data I actually need.
Yes, in my situation it is possible to use SQL and that would solve the challenge however, I would not like to go that way since a move to the cloud hopefully isn't that far away and I do not want to re-write all this logic when the move happens.
Yes, it would be possible to retrieve all data and make the comparison after the retrieval of data but the performance would be really bad since it would require to fetch basically every single account and contact from the system.
So, to solve the challenge I ended up in splitting the query up in 2 queries. The first one just retrieves all records where the socical security number didn't match the organization number. The second one I did the same way, just changed the fields to the other couple of fields I needed to compare.
How I made the query (simplified):
<fetch top="50">
<entity name="contact">
<attribute name="contactid" />
<attribute name="fullname" />
<filter>
<condition entityname="oouterAcct" attribute="accountid" operator="null" />
</filter>
<link-entity name="account" from="primarycontactid" to="contactid" link-type="inner" alias="innerAcct">
<attribute name="name" />
</link-entity>
<link-entity name="account" from="name" to="fullname" link-type="outer" alias="oouterAcct" />
</entity>
</fetch>