Shuold I use does not exist or join the instruction to filter NULL?

SELECT  *
FROM    employees e
WHERE   NOT EXISTS
        (
        SELECT  name 
        FROM    eotm_dyn d
        WHERE   d.employeeID = e.id
        )

AND

SELECT * FROM employees a LEFT JOIN eotm_dyn b on (a.joinfield=b.joinfield) WHERE b.name IS NULL

Which is more efficient, some analysis?

+1
source share
2 answers

Assuming column values cannot be NULL -

MySQL

LEFT JOIN/IS NULL more effective than NOT EXISTS- read this article for more details .

Oracle:

They are equivalent .

SQL Server:

NOT EXISTS more effective than LEFT JOIN/IS NULL- read this article in more detail .

Postgres:

Like Oracle, they are equivalent .

, , LEFT JOIN/IS NULL - , LEFT JOIN. .

+4

, . , .

! , , . employee eotm_dyn, IMO WHERE NOT EXISTS. , , , SELECT 1 (not SELECT name), name " eotm_dyn.

, , , , .

+2

Source: https://habr.com/ru/post/1738002/


All Articles