match values, then update fields

  • Thread starter Thread starter jennifer
  • Start date Start date
J

jennifer

I need to match field values in 2 tables, then update
fields in table A with data from table B if there is a
match. If there is no match in table A - I need to add a
new record and fill it with info from table B.
 
1. UPDATE A INNER JOIN B ON A.id = B.id SET A.f1 = .[f1], .... ;

2. INSERT INTO A ( id, f1,... ) SELECT B.id, B.f1, ...
FROM A RIGHT JOIN B ON A.id = B.id
WHERE A.id Is Null;
 
Back
Top