Tout d'abord, pas besoin de distinct . La requête peut être écrite comme :
select *
from example@sqldat.com
where column1 in (
select column2
from example@sqldat.com
where column3 > 0
)
order by column1
Deuxièmement, il y a (au moins) deux autres façons de l'écrire. Soit avec 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 (ma préférence) avec 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
Dans tous les cas, vous devez vérifier les plans d'exécution pour chacun d'eux.
Je m'attendrais à ce que les performances soient meilleures si vous avez un index sur table1.column1 et pour table2 , soit un index sur column2 ou un index composite sur (column3, column2)