Alternatively oracle DISTINCT with EXISTS

When submitting a to-many table information (such as department table and the Employees table) the query contains, avoid using DISTINCT in the SELECT clause. Generally consider replacing EXIST use

 E.g:

Inefficient:

    SELECT DISTINCT DEPT_NO,DEPT_NAME

    FROM DEPT D,EMP E

    WHERE D.DEPT_NO = E.DEPT_NO

Efficient:

    SELECT DEPT_NO,DEPT_NAME

    FROM DEPT D

    WHERE EXISTS ( SELECT ‘X’

                    FROM EMP E

                    WHERE E.DEPT_NO = D.DEPT_NO);

  EXISTS make queries more quickly, because the RDBMS kernel module in the subquery once the conditions are met, immediately returns the result.

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11124567.html