I have two tables (table1 and table2) which both have similar data. Both table1 and table2 have over 100000 records each in them. I need to concatenate three columns that are in table1 and compare them to three similar concatenated columns that are
in table2. The result that I am looking for is a list of items that are in table1 but not in table2. I have used the following query which works but is very slow, sometimes it takes over 60 seconds to run:
SELECT DISTINCT
Lower(Division + ' ' + Branch + ' ' + Program) AS Combined
FROM
table1
WHERE
Lower(Division + ' ' + Branch + ' ' + Program) NOT IN
(SELECT Lower(Division + ' ' + Branch + ' ' + Program) FROM table1)
I am wondering if there is a better/faster way to get the list that I need, possibly by using a join?
Thanks,
SELECT DISTINCT
Lower(Division + ' ' + Branch + ' ' + Program) AS Combined
FROM
table1
WHERE
Lower(Division + ' ' + Branch + ' ' + Program) NOT IN
(SELECT Lower(Division + ' ' + Branch + ' ' + Program) FROM table1)
I am wondering if there is a better/faster way to get the list that I need, possibly by using a join?
Thanks,