SQL - Check table for new rows?

sql

Solution

I would use a NOT EXISTS structure.

SELECT Name, Color
FROM TableA
WHERE NOT EXISTS (
SELECT 1 FROM TableB
WHERE TableA.Name = TableB.Name 
AND TableA.Color = TableB.Color)

Problem

I have two tables, for example: ``` Table A Table B ======= ======= Name | Color Name | Color ---------------------- ---------------------- Mickey Mouse | red Mickey Mouse | red Donald Duck | green Donald Duck | blue Donald Duck | blue Minnie | red Goofy | black Minnie | red ``` Table A is my source table and B is the destination table. Now I need a query which finds all the different (additional) rows in table A so table B can be updated with those rows. So I need a query which finds me the following rows from table A: ``` Name | Color ---------------------- Donald Duck | green Goofy | black ``` What is a good approach for such a query? It should be as efficient as possible (avoid too many joins). Thanks for any help!

Original source