Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Replace Distinct and where not exists for better Performance.

user13034857Feb 26 2021

Hello all,
I have a sql to tune for better performance.
I want a distinct record on few fields in a table1, and also, the distinct records does not exist in table2. I have SQL like this.
select distinct id
,dob
,file_name
from table1
where not exists(select id from table2
where table2.id=table1.id
and table2.dob=table1.dob
and table2.file_name=table1.file_name);
These tables have millions of records, and it is executing for a long time.
Could you please let me know how to increase performance for this sql? I created indexes for all the fields in the where clause.
Thank you.

Comments
Post Details
Added on Feb 26 2021
10 comments
4,314 views