I'm working on a query to find records in a table of new entries that match records in a table of historical entries, where the match could be on one of many fields. In other words:
"Show all records where current.id = archive.id or current.name = archive.name or current.address = archive.address"
My SQL for this query is as follows:
SELECT current.id, current.name, current.address FROM current
INNER JOIN archive
ON
current.id = archive.id OR
current.name = archive.name OR
current.address = archive.address
When I run it, it takes FOREVER, and this is on the first load of data; archive will always have around 300,000 records in it, but current will fluctuate between 500 and 40,000.
Is there a better way to write this query? Or, is my query solid, but my underlying database potentially in trouble?