What's the difference between 'not in' and 'not exists'?

前端 未结 4 1849
野的像风
野的像风 2021-02-02 15:08

What\'s the difference between not in and not exists in an Oracle query?

When do I use not in? And not exist?

4条回答
  •  别跟我提以往
    2021-02-02 15:36

    There can be performance differences, with exists being faster.

    The most important difference is the handling of nulls. Your query might seem to work the same with both in and exists, but when your sub-query returns null you might get a shock.

    You might find that the existence of nulls causes exists to fail.

    See Joe Celko's 'SQL for smarties' for a better explanation of when to use each.

提交回复
热议问题