sql join有重复项

时间:2015-04-21 21:51:51

标签: sql linq duplicates

我的左外连接保持返回完全重复,直到我向查询添加了distinct。这是为什么?如何将此查询转换为LINQ:

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

1 个答案:

答案 0 :(得分:0)

这是一个疯狂的猜测,我知道我可能会得到这个但是

检查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