2015-04-21 37 views
0

我的左外連接保持返回確切的重複,直到我添加不同的查詢。這是爲什麼?而且我怎麼能這個查詢轉換爲LINQ:sql連接有重複

SELECT distinct 
    ADCIC.AccountDairyToCommitmentItemCategoryID, 
    ADCIC.AccountDairyParentID  
from 
    vw_ParentAccountDollarsAllocatedByCommitmentItemCategory vw 
    left outer join tblAccountDairyToCommitmentItemCategory ADCIC 
    ON vw.AccountDairyParentID = ADCIC.AccountDairyParentID   
where 
    vw.FiscalYear = 2015 
    AND vw.AccountDairyParentID = 6478 
+2

您可能要問了一個新問題的查詢轉換爲L INQ,因爲它是一個明顯的問題 –

+0

左連接不會返回重複項,但是除非您選擇*,否則您可能不會看到值的唯一性。不同將會限制查詢到您選擇的那些列的不同值。 – paqogomez

+0

至於linq問題,這是一個簡單的問題,並有[左連接的例子很多](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8 #q = linq%20left%20join%20example)在那裏。 – paqogomez

回答

0

這是胡亂猜測,我知道我可能會得到downvotes對於這一點,但

檢查tblAccountDairyToCommitmentItemCategory表有FiscalYear列,如果是的話,我認爲你需要在您的加入條件添加FiscalYear

你可能想嘗試以下查詢

SELECT 
    ADCIC.AccountDairyToCommitmentItemCategoryID, 
    ADCIC.AccountDairyParentID  
from 
    vw_ParentAccountDollarsAllocatedByCommitmentItemCategory vw 
    left outer join tblAccountDairyToCommitmentItemCategory ADCIC 
    ON vw.AccountDairyParentID = ADCIC.AccountDairyParentID 
    and vw.FiscalYear = ADCIC.FiscalYear 
where 
    vw.FiscalYear = 2015 
    AND vw.AccountDairyParentID = 6478