I have two very large tables, Table1 and Table2. They look like this:
Table1 (800k records): Name, BirthDate, OrderNumber, col4, col5, col6.
Table2 (200k records): Name, BirthDate, OrderNumber, col4, col5, col6.
How can I select all records from table 1 which don’t have a matching Name, BirthDate, OrderNumber combination in table 2? The rest of the columns don’t matter.
I’ve tried doing this query below which runs for at least a couple minutes with no apparent end. Right now I am just trying to select the records then i can figure out how to combine the tables.
Select Table1.Name, Table1.BirthDate, Table1.OrderNumber from Table1
left join Table2 ON
Table1.Name=Table2.Name AND
Table1.BirthDate=Table2.BirthDate AND
Table1.OrderNumber=Table2.OrderNumber AND
WHERE Table2.Name IS NULL;
You can try this variation and see if it’s any better. You should also make sure you have Name, BirthDate and OrderNumber indexed.