I have two table in SqlServer Member and MemberAdress and I am generating a view vw_Member by executing following query
SELECT
m.MemberId,
m.MemberName,
m.EndCustomer,
m.ExpirationDate,
ma.DEA,
ma.HIN,
ma.Address1,
ma.Address2,
ma.City,
ma.State,
ma.OfficeContact,
ma.OfficeContactTitle,
ma.OfficeContactEmail
FROM dbo.Member m
INNER JOIN dbo.MemberAddress ma ON (m.MemberId = ma.MemberId)
but the problem is that I am generating two record for unique MemberId
Can Somebody tell me what I am doing wrong ?
Wild guess – there are two rows in
MemberAddresswith the sameMemberId. Maybe there’s some concept modelled in there of an address type? If so, you need to decide which of those address types you should be including in this view, or if you always need an address, some decision on how you would prioritise the address types.For the second, your FROM clause might look something like:
Where the join to
ma_antiis trying to find a “better” row fromMemberAddressthan the row selected fromma– if the join succeeds, you don’t want that row in your final result set, so that’s what theWHEREclause is doing.