Supposing we have
Table A
field 1 | field 2
orange | fruit
apple | fruit
and
Table B
field 1 | field 2
orange | fruit
lemon | fruit
And want to insert only the rows from Table B to Table A that don't match on field 1 so that Table A becomes:
Table A
field1 | field2
orange | fruit
apple | fruit
lemon | fruit
Ive tried
insert into tableA (field1, field2)
select field1, field2 from tableB
where not exists
(select * from tableA as a join tableB as b on a.field1 = b.field1)
(no insert)
and
insert into tableA (field1, field2)
select field1, field2 from tableA as a left join tableB as b on a.field1 = b.field1
union
select field1, field2 from tableA as s right join tableB as b on a.field1 = b.field1
where a.field1 != b.field1
(incorrect insert)
INSERT INTO tableA (field1, field2) SELECT b.field1, b.field2 FROM tableA a LEFT JOIN tableB b USING field1 WHERE a.field1 IS NULLI think is what you're looking for. Start off by figuring out the SELECT that you want (all rows from tableB that are not in tableA), and then insert only those rows.