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

后端 未结 2 1814
不知归路
不知归路 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 19:59

    I really think you should profile for such a question. Not only does it depend on the exact database product, but in theory it could also depend on the skew of your data.

    However! By default I would say write the code that most clearly expresses your intent. You are after employee records without a matching eotm_dyn, so IMO the clearest code is WHERE NOT EXISTS. It probably won't matter, but I would use SELECT 1 (not SELECT name), since the name is not important in the "without a matching eotm_dyn logic.

    Once you have code that expresses what you intend and works, then look at optimising based on profiling.

提交回复
热议问题