PDA

View Full Version : comparison query


jedimastermopar
12-28-2006, 09:26 PM
I have two tables,
I have a company table and a client table
The fields in question are as follows

Company.companyid
Company.maincontactid
Contact.contactid

Due to bad design and bad data entry we have a bunch of companies with a contact number but no entry in the contact table. I want to run a query to dump a list of Company.companyid and Company.maincontactid where Company.maincontactid has no corrisponding Contact.contacid

jedimastermopar
12-28-2006, 09:32 PM
Or even better code to take the output of the above code and create a corrisponding entry into the contact table with Company.companyname as the contact.contactname and Company.maincontactid as Contact.contactid

guelphdad
12-28-2006, 10:12 PM
do an outer join and test for nulls or do a NOT IN subquery.