嵌套Select Distinct并返回Joined表中的所有结果

时间:2013-08-15 19:30:43

标签: sql select join nested

我有两个表,它们都有MemberId个共同点。我只想返回余额大于0.00的明确帐户和结算通知= 2,其中结果在特定日期之后。到目前为止我想出的是:

use Plantation
select tblmember_v62.Acct, tblmember_v62.First, tblmember_v62.Last, tblMemberAccount_v62.Balance
from tblmember_v62, tblMemberAccount_v62
Where dbo.tblMember_v62.MemberId = tblmemberaccount_v62.MemberId
and tblMemberAccount_v62.Balance > '0.00' and tblMember_v62.BillingNotify = '2'
and (tblMemberAccount_v62.InsertDate > '2012-01-01 00:00:00.000' or tblMemberAccount_v62.UpdateDate > '2012-01-01 00:00:00.000')
Order by dbo.tblMemberAccount_v62.MemberId, tblmember_v62.Last

我怎样才能返回不同的结果?我知道它应该不那么难......

1 个答案:

答案 0 :(得分:0)

use Plantation

select distinct tblmember_v62.Acct, tblmember_v62.First, tblmember_v62.Last, tblMemberAccount_v62.Balance

from tblmember_v62, tblMemberAccount_v62

Where dbo.tblMember_v62.MemberId = tblmemberaccount_v62.MemberId
and tblMemberAccount_v62.Balance > '0.00' and tblMember_v62.BillingNotify = '2'
and (tblMemberAccount_v62.InsertDate > '2012-01-01 00:00:00.000' or tblMemberAccount_v62.UpdateDate > '2012-01-01 00:00:00.000')

Order by dbo.tblMemberAccount_v62.MemberId, tblmember_v62.Last