Query Optimization - Not In NOT IN clause in Oracle is very expensive and let the optimizer FULL Scan your tables. Because NOT IN does not use a limiting condition. A way to overcome this problem is to rewrite the query with OUTER JOIN. Outer Joins adds a limiting condition to your queries that can reduce the number of full table scans necessary Example of NOT IN ----------------------------- SELECT * FROM MYEMP WHERE DEPTNO NOT IN ( SELECT DEPTNO FROM MYDEPT ); Above query with Outer Join ----------------------------- SELECT MYEMP.* FROM MYEMP, MYDEPT WHERE MYEMP.DEPTNO = MYDEPT.DEPTNO(+) AND MYDEPT.DEPTNO IS NULL; Get More Query Optimization Tips: http://nimishgarg.blogspot.in/2012/10/query-optimization-tips-for-oracle.html
Query Optimization - Not In
Subscribe to:
Post Comments (Atom)
Hi ,
ReplyDeleteThe above join query,wil it possible to write it by using EXISTS operator ..?
Plz let me know..???
SELECT * FROM MYEMP e
DeleteWHERE NOT exists
(
SELECT 1 FROM MYDEPT d where e.DEPTNO = d.DEPTNO
);
But join works efficiently (especially when the columns have index on them) than EXISTS since exists will check for each and every rows individually.
ReplyDeletehow can we compare both query as not in means not equal(not match) and join means equal(same match)please explain
ReplyDeleteSQL – IN, NOT IN Operatörü ve Kullanımı – Ders 14
ReplyDeleteOperatörler ve SQL’deki kullanımları ile ilgili anlatımlara IN, NOT IN operatörlerini anlatarak devam edelim. Efektif bir şekilde kullandığımızda işimize yarayacak bu operatörlerin syntaxı ve ne gibi problemlerde kullanılacağını yazıda detaylı olarak anlatmaya çalıştım.
https://www.dogushan.com/sql-in-not-in-operatoru-ve-kullanimi-ders-14/
gümüşhane
ReplyDeletebilecik
erzincan
nevşehir
niğde
P7T76C