mySQL:如何从列表中的表中选择而不是在另一个列表中
是否可以从表中选择值,这些值不存在于一个列表中,但确实存在于另一个列表中......或者反之亦然?
例如
SELECT COUNT(g.`property`) as `number`, g.`property`
FROM `foo` g
WHERE `theID` IS IN (SELECT `theID`
FROM `tableofIDS`
WHERE `theID` = '54252')
AND NOT IN (SELECT `theID`
FROM `anotherTableofIDS`
WHERE `theID` = '54252')
Is it possible to select values from a table, where they don't exist in one list, but do exist in another... or they other way around?
E.g.
SELECT COUNT(g.`property`) as `number`, g.`property`
FROM `foo` g
WHERE `theID` IS IN (SELECT `theID`
FROM `tableofIDS`
WHERE `theID` = '54252')
AND NOT IN (SELECT `theID`
FROM `anotherTableofIDS`
WHERE `theID` = '54252')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者,您可以使用性能更好的联接:
Alternativly, you can use joins which will perform better:
没有仔细思考,但发现了两个语法错误。尝试
编辑:将
NOT IN
更改为NOT EXISTS
Didn't think it through but discovered 2 syntax errors. Try
Edit: Changed
NOT IN
toNOT EXISTS
我想也许你正在寻找的是这样的:
I think maybe what you're looking for is just this: