加入返回多个结果

时间:2013-09-23 14:03:57

标签: tsql join

漫漫长夜,我正在努力解决这个问题。

我有一个查询,它返回多行,结果相同。

SELECT        apf_Members.AppsTitle, apf_Members.AppsFirstName, apf_Members.AppsLastName, vw_apf_MemStat.MemberID, vw_apf_MemStat.DNNUserID, 
                         vw_apf_MemStat.MemStat_LapsedMember, vw_apf_MemStat.MemStat_CurrentMember, vw_apf_MemStat.MemStat_Unrenewed, 
                         apf_Members.MemberID AS Member, apf_Members.PostalCompany AS Company, apf_Members.AppsFirstName AS FirstName, 
                         apf_Members.AppsLastName AS LastName, apf_Members.AppsBirthDate AS DOB, apf_Members.PostalState AS State 

FROM            apf_Members INNER JOIN
                         vw_apf_MemStat ON apf_Members.MemberID = vw_apf_MemStat.MemberID INNER JOIN
                         vw_apf_AttributesConditions ON apf_Members.MemberID = vw_apf_AttributesConditions.MemberID


WHERE        (vw_apf_MemStat.MemStat_CurrentMember <> - 1) AND (vw_apf_AttributesConditions.AttributeID = 7)
ORDER BY apf_Members.AppsLastName, State, apf_Members.MailOption

如何停止重复行?对于每个重复的行,列看起来完全相同,因此它们肯定是重复的。

我假设它是2x内连接,但我似乎无法解决它。

谢谢大家,

-R

1 个答案:

答案 0 :(得分:1)

在三个表上

select memberID, count(*) 
  from table 
 group by memberID 
having count(*) > 1