Need some help with SQL Join statements please
-
Hi, I have 3 tables. 1. A contact table 2. A company table 3. A company to contact association table. If a company to contact association is created, a field, 'CompanyName', in the contact table needs to contain the name of that company (in order for our mailing lists to print correctly). I've been trying to write a query which will fill in all of the contact table 'CompanyName' values, with all of the corresponding values in the company table. The company to contact association table is the link between the two so: 1. I need to determine which contact's have an association with a company 2. I need to get the companyID from the association table, and get the company name 3. I need to set the contact company name to the retrieved value. Only problem is... IM STUCK!!! This is what i've done so far.
SELECT Contacts.CompanyName FROM MarkSandpit.dbo.Contacts INNER JOIN MarkSandpit.dbo.Associations_Companies_to_Contacts ON Contacts.mxContactID = Associations_Companies_to_Contacts.mxContactID INNER JOIN mxContact.dbo.Companies ON Associations_Companies_to_Contacts.mxCompanyID = Companies.mxCompanyID
This just gives me a list of all the company names in the contact table, which have associations with a company. Could some please help me out? Cheers,Mark Brock "We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen Click here to view my blog