我有一个跨 2 个未返回任何结果的表的 SELECT 查询,我不知道为什么不返回。这是不返回任何行的查询:
SELECT b.name, b.description, b.badge_id
FROM badges AS b
WHERE b.type = 'have' AND b.brand_id = 'zTR7wH5FMl' AND ISNULL(b.series_id) AND b.amount <= 89
AND NOT EXISTS (SELECT date_earned
FROM users_badges AS ub
WHERE ub.user_id = 'fMcBBx' AND ub.badge_id = b.badge_id)
如果我只是在最后去掉 AND NOT EXISTS 子句以检查他们是否还没有获得徽章,我会得到这些结果:
name description badge_id
Baker's Dozen Add 13 items to your Johnny Cupcakes shelf. sdfKHJkun7
Cupcaker Have 82 items on your Johnny Cupcakes shelf. 4MeoheBdik
Freshly Baked Have your first item on your Johnny Cupcakes shelf... kdJGH98NdI
这正是我期望得到的。AND NOT EXISTS 检查是唯一的区别。users_badges 表中还没有数据,所以我不明白为什么它会返回 false。在我看来,它将无法返回 false。为什么它会使整个查询无效?