Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Need help to speed up a qurey.

$
0
0
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,

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>