Link to home
Start Free TrialLog in
Avatar of David Glover
David GloverFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How do I add new rows to a new table where there isn't an existing row that matches the foreign key?

I want to create records in a table with a value for every matching record in another table  but only if there isn't already a record.
So for the following :
Customers                  Locations      
CustomerID                  CustomerID      Location
1                  2      Unknown
2                  3      England
3                  4      Spain
4                        
5                        

I would like for the sql command to end up with the tables looking like this:
Customers                  Locations      
CustomerID                  CustomerID      Location
1                  1      Unknown
2                  2      Unknown
3                  3      England
4                  4      Spain
5                  5      Unknown
ASKER CERTIFIED SOLUTION
Avatar of UnifiedIS
UnifiedIS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Guess, we had the same thought, UnifiedIS. :)
Avatar of David Glover

ASKER

Thanks guys, I split the points on this occasion because you actually seemed to answer simultaneously!
Thanks again,