I need to copy over rows from Table B to Table A. The requirement is to only insert rows that are not already in A.
My question is, which is of the the following two is more efficient:
A)
INSERT INTO A (x, y, z)
SELECT x, y, z
FROM B b
WHERE b.id NOT IN (SELECT id FROM A);
B)
INSERT INTO A (x, y, z)
SELECT b.x, b.y, b.z
FROM B b LEFT OUTER JOIN A a
ON b.id = a.id
WHERE a.id is NULL;
I am assuming the answer depends upon the size of the tables. But I wanted to know if there is something glaringly obvious about using one approach over the other.
To reduce the vagueness, lets say Table B will have less than 50K rows, and Table A will always be equal to or greater in size to Table B by a factor of 1-5.
If anyone has any other more efficient ways to do this, do tell.