>I have 2 tables with same structure where most of the records are the same between the two. However, I need to determine which records in table1 are not in table2 and vice versa.
>
>I am using the following
>
>
>SELECT table1.pk as pk1, table2.pk as pk2 ;
> FROM ;
> table1 ;
> left OUTER JOIN table2 ;
> ON table1.pk = table2.pk WHERE table2.pk is null
>
>
>
>and then
>
>
>
>SELECT table1.pk as pk1, table2.pk as pk2 ;
> FROM ;
> table2 ;
> left OUTER JOIN table1 ;
> ON table2.pk = table1.pk WHERE table1.pk is null
>
>
>Is there a better way to come up with the missing records from one table to the next?
I think this is the best approach you took. You can also use where NOT IN (select ID from table2) or NOT EXISTS.
If it's not broken, fix it until it is.
My Blog