0

我最后一个问题的后续行动。请注意,这不是重复的,另一个问题是缺少WHERE我拥有的一个子句;)。

我想我有两个相同的变体,带有健全性检查。我的问题是 - 一个什么都不返回,而另一个返回我所期望的。我的问题是我不明白为什么 - 有人可以在这里帮助我吗?

一切都是 SQLite3。

变体 1:

select
    z.license,
    z.username
from
    check_table as z
where
    (
        z.username not in (
            select a.mail_username
            from Address as a 
        )
    )
order by
    license, username;

变体 2:

select
    z.license,
    z.username
from
    check_table as z
where
    (
        not exists (
            select 1
            from Address as a
            where z.username = a.mail_username
    )
)
order by
    license, username;

完整性检查:

select
    z.username,
    a.mail_username
from
    check_table as z
    left join Address as a
        on z.username = a.mail_username
where
    a.mail_username is null
order by
    mail_username

结果:

  • 变体 1 什么都不返回,但 IMO 应该(0.004 秒)
  • 变体 2 返回 265 个结果(0.097 秒)
  • 变体 3 返回 265 个结果(0.004 秒)

我完全迷失了,因为NOT IN在其他组合中工作得很好,我看不出有什么区别。

更新:好的,它是重复的 :D 。为我辩护 - 实际的原件有一个非常不起眼的名字;)

4

0 回答 0