Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find missing records and append 1

Status
Not open for further replies.

Lost500

IS-IT--Management
Joined
Mar 10, 2009
Messages
110
Location
US
Hello all!
I would like to create a query to compare the ID fields in two tables and find which records are missing in table B (table A has them all) and append them to table B leaving both tables with all the same ID numbers.

Table A is the Primary key including all ID numbers and Table B has most of the records with additional information so i cant just cut and paste. only the id field needs to be appended. I need to do this so that i can create a relationship between the two tables that will cascade any changes/deletes/additions so this wont happen again!

I know the correct course of action is to create the relationship when the tables are created so that they will always have the same ID numbers but, i get handed alot of crap so here we are [thumbsup2]

Please adivise and thanks in advance y'all are great.
 
I guess something on the lines of:

Code:
INSERT INTO TableB ( ID )
SELECT ID FROM TableA
LEFT JOIN TableB
ON TableA.ID=TableB.ID
WHERE TableB.ID Is Null

 
Thanks Remou that got me pointed in the right direction and ended up working great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top