INNER JOIN Excellent ID

I have the following code:

FROM CTE_Order cte
    INNER JOIN tblOrders o
       ON cte.OrderId = o.Id
    INNER JOIN tblOrderUnits ou
       ON o.id = ou.OrderId                        
    INNER JOIN tblOrderServiceUnits osu
       ON ou.VMSUnitID = osu.UnitId

When I join ou, I get 2 identical unit identifiers. This causes Inner Join tblOrderServiceUnits to return 4 rows with 2 duplicates. I need it to return only two rows. How to use separate inner join only separate ou.id file?

Sorry for the poor explanation, but basically I'm jsut trying to figure out how INNER JOIN works with a separate subquery. If someone can give me an example of what I could understand it from there.

+5
source share
1 answer
INNER JOIN (SELECT DISTINCT * FROM X) Alias
ON Alias.ID = Primary.ID

In your example:

INNER JOIN (SELECT DISTINCT VMSUnitID, OrderId FROM tblOrderUnits) ou
ON o.id = ou.OrderId
+12
source

All Articles