I'm having trouble with a select, I have one table that holds all my interests for specific contacts, but am having trouble getting a single Interest in the select (there are interestTypes). Kind of hard to explain, It'd be easier if i just posted the SQL and have a look:I'd like the result set to look like this:ContactID ContactName InterestApparel InterestVehicle ----------- -------------------- -------------------- -------------------- 1 John Doe Shoes Toyota2 Jane Doe Clothes NULLbut it's coming out with multiple contacts like so ... ContactID ContactName InterestApparel InterestVehicle ----------- -------------------- -------------------- -------------------- 1 John Doe Shoes NULL1 John Doe Shoes Toyota1 John Doe NULL NULL1 John Doe NULL Toyota2 Jane Doe Clothes NULLset nocount ondeclare @ContactInterest table ( ContactID int, InterestID int)declare @Contact table ( ContactID int PRIMARY KEY, ContactName varchar(255))declare @Interest table ( InterestID int PRIMARY KEY, InterestTypeID int, InterestName varchar(255))insert into @Contact select 1, 'John Doe'insert into @Contact select 2, 'Jane Doe'insert into @ContactInterest select 1,1insert into @ContactInterest select 1,4insert into @ContactInterest select 2,3insert into @Interest select 1, 1, 'Shoes'insert into @Interest select 2, 1, 'Socks'insert into @Interest select 3, 1, 'Clothes'insert into @Interest select 4, 2, 'Toyota'insert into @Interest select 5, 2, 'Honda'insert into @Interest select 6, 2, 'Ford'select c.ContactID, c.ContactName, i.InterestName AS InterestApparel, i2.InterestName AS InterestVehiclefrom @Contact c LEFT OUTER JOIN @ContactInterest ci on c.ContactID = ci.ContactID LEFT OUTER JOIN @Interest i on ci.InterestID = i.InterestID and i.InterestTypeID = 1 LEFT OUTER JOIN @ContactInterest ci2 on ci2.ContactID = c.ContactID LEFT OUTER JOIN @Interest i2 on ci2.InterestID = i2.InterestID and i2.InterestTypeID = 2set nocount offI also tried this select, but then it does not include contacts that don't have a specific interest for that type:select c.ContactID, c.ContactName, i.InterestName AS InterestApparel, i2.InterestName AS InterestVehiclefrom @Contact c LEFT OUTER JOIN @ContactInterest ci on c.ContactID = ci.ContactID LEFT OUTER JOIN @Interest i on ci.InterestID = i.InterestID LEFT OUTER JOIN @ContactInterest ci2 on ci2.ContactID = c.ContactID LEFT OUTER JOIN @Interest i2 on ci2.InterestID = i2.InterestIDwhere i.InterestTypeID = 1 and i2.InterestTypeID = 2
any help would be GREATLY appreciated.