Primeiro, não há necessidade de
distinct . A consulta pode ser escrita como:select *
from example@sqldat.com
where column1 in (
select column2
from example@sqldat.com
where column3 > 0
)
order by column1
Segundo, existem (pelo menos) mais duas maneiras de escrevê-lo. Ou com
JOIN :select t1.*
from example@sqldat.com t1
join example@sqldat.com t2
where t2.column2 = t1.column1
and t2.column3 > 0
group by
t1.id, t1.column1, ...
order by t1.column1
ou (minha preferência) com
EXISTS :select t1.*
from example@sqldat.com t1
where exists
( select *
from example@sqldat.com
where t2.column2 = t1.column1
and t2.column3 > 0
)
order by column1
De qualquer forma, você deve verificar os planos de execução de todos eles.
Espero que o desempenho seja melhor se você tiver um índice em
table1.column1 e para table2 , ou um índice em column2 ou um índice composto em (column3, column2)