Below is my query that takes more than 2 hours to retrieve the result, and I am not sure why. These tables have 200 000 records.

```
    INSERT INTO tempoutput12345 (tempitm, templitm, URRF_Configurator_Item) 
    SELECT DISTINCT 
        [KYKIT] 'IBITM', iblitm, 'CFG_ITEM' 
    FROM  
        [database].[production].[PRODDTA].[tableF3293] with (nolock)
    JOIN  
        [database].[production].[PRODDTA].[tablef4102] with (nolock) ON  
    kykit = ibitm 
    WHERE
        EXISTS (SELECT templitm FROM tempoutput12345 
                WHERE templitm = iblitm)
        AND IBMCU LIKE '%'+'5217194'
        AND 1 = 1

    UNION ALL 

    SELECT DISTINCT
        [KYITM] 'IBITM', iblitm, 'CFG_ITEM' 
    FROM     
        [database].[production].[PRODDTA].[tableF3293] with (nolock) 
    JOIN     
        [database].[production].[PRODDTA].[tablef4102] with (nolock) ON 
    kyitm = 

    ibitm 
    WHERE 
        EXISTS (SELECT templitm FROM tempoutput&jobid& 
                WHERE templitm = iblitm)
        AND IBMCU LIKE '%'+'5217194'
        AND 1 = 1

    UNION ALL 

    SELECT DISTINCT 
        [RDITM] 'IBITM', iblitm, 'CFG_ITEM' 
    FROM    
        [database].[production].[PRODDTA].[tableF3283] with (nolock)
    JOIN     
        [database].[production].[PRODDTA].[tablef4102] with (nolock) ON 
    rditm = ibitm 
    WHERE    
        EXISTS (SELECT templitm FROM tempoutput&jobid& 
                WHERE templitm = iblitm) 
        AND IBMCU LIKE '%'+'5217194'
        AND 1 = 1;

```

The above query will take longer time. please help me it out for this