ONE field is causing problem. Please help
680651Aug 24 2009 — edited Aug 24 2009Hello experts,
I’m trying to get some data from 4 different tables and having a little difficulty. I need you experts help in this regards. I’ve got 4 tables. ActiveMembers, Member_lookup, Name, Corp. I need 3 fields from ActiveMem, 1 Fields from Member_Info, 2 fields from Name and 1 from Corporate_Info.
ActiveMem, Member_Info and Name has a common field MEM_TYPE. So I used LEFT OUTER JOIN to join them. I also joined ActiveMem with Corporate_Info with ID which is common.
I’ve achieve what I want but there is 1 field which is messing up things. This field causing so many repetitions and it is coming from Name table. I’m selecting 2 fields from this table MEM_STATUS AND MEM_STATUS_DATE. When I join all 4 table using Left Outer Join WITHOUT MEM_STATUS_DATE then I don’t get any repetition and everything looks great.
Here is the sample of out
CHAR 229657 Serco Operations Training and Project Development Manager Champion D
CHAR 232458 UPS Canada Director of Business Development Champion D
CHAR 231850 Cybernomics Infrastructure & Support Analyst Champion D
CHAR 22811 George Weston Limited Champion D
CHAR 229654 Serco Director of Operations Champion D
However as soon as I add this field in my query it causes so many repetitions.
Here is the sample of out put
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 4/6/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 4/8/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 4/9/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 4/29/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 4/30/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 5/1/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 5/14/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 5/19/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 5/28/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 6/8/2009 12:00:00 AM
CHAR 13452 Bombardier Commercial Aircraft Vice President, Services Bombrardier Transportation North America Champion D 6/29/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 4/6/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 4/8/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 4/9/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 4/29/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 4/30/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 5/1/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 5/14/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 5/19/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 5/28/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 6/8/2009 12:00:00 AM
CHAR 14775 Toromont Cat Vice President, Power Systems and Energy Champion D 6/29/2009 12:00:00 AM
Can anybody point out what mistake I’m making here? For reference here is my query.
Thanks,
SELECT DISTINCT
dbo.ActiveMembers.MEMBER_TYPE, dbo.ActiveMembers.ID, dbo.ActiveMembers.COMPANY, dbo.ActiveMembers.TITLE,
dbo.Member_Lookup.NEW_MEMBER_CLASS, dbo.Name.MEMBER_STATUS, dbo.Name.MEMBER_STATUS_DATE, dbo.CORP.CONTACTNAME
FROM dbo.CORP LEFT OUTER JOIN
dbo.ActiveMembers ON dbo.CORP.ID = dbo.ActiveMembers.ID LEFT OUTER JOIN
dbo.Member_Lookup ON dbo.ActiveMembers.MEMBER_TYPE = dbo.Member_Lookup.MEMBER_TYPE LEFT OUTER JOIN
dbo.Name ON dbo.ActiveMembers.MEMBER_TYPE = dbo.Name.MEMBER_TYPE
WHERE (dbo.Name.MEMBER_TYPE IN ('GROR', 'CHAR', 'PRER')) AND (dbo.Name.MEMBER_STATUS = 'D') AND
(dbo.Name.MEMBER_STATUS_DATE BETWEEN '4/1/2009' AND '6/30/2009')
ORDER BY dbo.ActiveMembers.MEMBER_TYPE
Thanks a lot in Advance.