Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Joining Entities on Specific Column Only

(0) ShareShare
ReportReport
Posted on by 5

I have a two tables in SQL Server, for the purpose of this question, lets say they are called TableA and TableB.

Both of these tables contain an Id column which can be used to join the two tables together.

For example:

SELECT *
FROM TableA a
INNER JOIN TableB b on  a.Id = b.Id

In Dynamics, I have also created TableA and TableB, and imported the data.

Although I'm confused how to create a relationship based on the one specific Id column. If I create a relationship it seems to want to do its own join, so I'm getting stuck how do to this. Can anyone suggest a guide for this?

  • Anrini Profile Picture
    on at
    RE: Joining Entities on Specific Column Only

    I hope this will be useful

    www.sqlbi.com/.../

  • Suggested answer
    Wahaj Rashid Profile Picture
    11,321 on at
    RE: Joining Entities on Specific Column Only

    Hi,

    Thank you for your query.

    In Dynamics 365, you cannot create a relationship based on a custom column. The relationship is created on ID (primary) columns.

    For example, Opportunity table is joined using opportunityid column with Opportunity Product table.

    However, you can use Alternate Keys in your tables for this purpose:

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/define-alternate-keys-entity

    To give you perspective, let me brief on relationship types and their behavior using your example:

    • Table A 1 to N (many) Table B: this means Table B will have a lookup of Table A (based on tableAid column).
    • Table A N to 1 Table B: this means Table A will have a lookup field of Table B (based on tableBid)
    • Table A N to N Table B: a resolving entity (e.g. new_table_a_table_b) is created automatically with the following columns:
      • new_table_a_table_b_id (primary key of resolving table)
      • tableAid
      • tableBid

    Apart from an ID column, Dynamics 365 tables (entities) has a primary column (commonly named name). This is the value shown in the lookup field (for Display purposes, behind the scenes it is connected with the primary id).

    You can also create Alternate Keys (as mentioned before) in you entities.

    To summarize, you cannot create relationships based on your columns, however, if you still have a requirement you can add both custom columns as alternate keys in the tables and join them using SQL server query.

    Example:

    • Table A
      • tableAid (primary key created by the system)
      • tableAno (your custom column)
    • Table B:
      • tableBid (primary key created by the system)
      • tableAid (lookup to table A using primary column)
      • tableAno (custom column to hold value from Table, without a foreign key)

    Now it will be your responsibility to fill tableAno value when a record of table B is linked with Table B (either using a real-time workflow or plugin) or use relationship mapping.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,283 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,025 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans