【发布时间】:2015-02-03 11:46:32
【问题描述】:
有两张桌子:
wes - contains 8000 rows, with 2000 distinct masternames (mastername is a column in wes)
wem - contains 2100 rows, with 2100 distinct names (name is a column in wem)
我正在尝试获取 wem 中存在的名称,但不是 wes 中的 masternames:
SELECT name FROM wem WHERE name NOT IN (SELECT DISTINCT mastername FROM wes)
但由于某种原因,我的查询没有返回任何行,即使 wem 中有大约 100 个名称在 wes 中不作为 masternames 存在。
对出了什么问题有任何想法吗?
谢谢!
【问题讨论】:
-
两个表中的列类型是什么?
-
列的排序规则是什么?
-
你的sql语句似乎是正确的。我认为您应该再次检查名称是否真的不在 wes 表中并且确实在 wem 表中提交。可能会发生一些事情,比如您向我们插入了新记录,没有提交,并且在不同的会话中您尝试了 SELECT 语句。
标签: mysql sql select join distinct