I have the following SQL query with a LEFT JOIN
with an OR
condition which makes it almost unworkable - took over 12 hours and then had to be cancelled as it finished to complete.
Is there a better way to write it so it's runnable?
DROP TABLE IF EXISTS #temp_t
SELECT
txn.*
,lkp.ID, lkp.NAME, lkp.ADDRESS
INTO #temp_t
FROM master_txn as txn --43m rows
LEFT JOIN master_lookup as lkp --280k rows
ON ((txn.lkp_ID_1 = lkp.ID AND txn.Txn_Type = 'Sell')
OR (txn.lkp_ID_2 = lkp.ID AND txn.Txn_Type = 'Buy'))