Query keeps on executing I'm executing below query, but it keeps on executing.

In place of some time I have a time value.

select distinct(col1) 
from table1
where col2 &gt; 'some time'
  and col1 not in 
      (select distinct(col1) 
       from table2 
       where col2 not like '%XYZ%');
Apart from the fact that where not in () is almost always very slow, distinct will also be slow.

Try this, and let me know if it is better: 

select distinct(col1) 
from table1
    left join table2 on table1.col1 = table2.col1
        and table2.col2 not like '%XYZ%'
where table1.col2 &gt; 'some -time'
  and table2.col1 is null;


Note: You have to bear in mind that there could be a magnitude of other issues affecting the performance, such as hardware, indexing, other users etc.; the above query represents some improvement, but is not guaranteed to run blindingly quick.