まず、distinctは必要ありません 。クエリは次のように記述できます:
select *
from example@sqldat.com
where column1 in (
select column2
from example@sqldat.com
where column3 > 0
)
order by column1
第二に、それを書くには(少なくとも)さらに2つの方法があります。 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
または(私の好み)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
いずれにせよ、それらすべての実行計画を確認する必要があります。
table1.column1にインデックスがある場合、パフォーマンスは最高になると思います。 およびtable2の場合 、column2のインデックス または(column3, column2)の複合インデックス