Shuold I use not exists or join statement to filter out NULLs?

后端 未结 2 1835
不知归路
不知归路 2021-01-25 19:37
SELECT  *
FROM    employees e
WHERE   NOT EXISTS
        (
        SELECT  name 
        FROM    eotm_dyn d
        WHERE   d.employeeID = e.id
        )
2条回答
  •  轮回少年
    2021-01-25 20:07

    Assuming the column values involved can not be NULL -

    MySQL:

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

    Oracle:

    They are equivalent.

    SQL Server:

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

    Postgres:

    Like Oracle, they are equivalent.

    If you have trouble with the detail that the column values can not be null, yet use the LEFT JOIN / IS NULL - remember what a LEFT JOIN signifies. This link might help.

提交回复
热议问题