I’m trying to migrate some data from two tables into a new table and having a hard time figuring out how to do it.
Data:
table fh rows: A, B, C, X, Y
table fhgb rows: B, C
table gvsi (currently empty) rows: A, X, Y
A is unique, and B+C is unique
When done, table gvsi should contains all rows in fh where X=value and the row isn’t already in fhgb.
This is a one-time data migration to gvsi so performance isn’t a huge deal.
fh has 36 million rows with 12 million that I care about (where X=value).
fhgb has 10 million rows. I’m expecting gvsi to contain about 2 million rows (12mil-10mil) when done.
I’ve googled and tried lots of things but can’t get anything to work (JOINs, subqueries, etc.) Can anyone help me figure out how to do this?
Our DB guy came up with the answer in 2 minutes:
That’s not to say some of these answers won’t work, but this one worked first try. Thanks for looking at it. I should try some of these other answers too and see if they work and if they work faster.