本文介绍了MySQL:两个结果集的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获得两个结果集的集合差异?
How can I get the set difference of two result sets?
说我有一个结果集(每个结果中只有一列):
Say I have a result set (just one column in each):
result1:
'a'
'b'
'c'
result2:
'b'
'c'
我想通过result2减去result1中的内容:result1-result2等于:
I want to minus what is in result1 by result2: result1 - result2 such that it equals:
difference of result1 - result2:
'a'
推荐答案
要执行result1-result2,可以将result1与result2连接起来,并且只输出result1中存在的项目.例如:
To perform result1 - result2, you can join result1 with result2, and only output items that exist in result1. For example:
SELECT DISTINCT result1.column
FROM result1 LEFT JOIN result2 ON result1.column = result2.column
WHERE result2.column IS NULL
请注意,这不是集合 difference ,并且不会在result2中输出在result1中不存在的项目.设置为减法.
Note that is not a set difference, and won't output items in result2 that don't exist in result1. It's set subtraction.
另请参见:相关博客文章的网络存档版本.
这篇关于MySQL:两个结果集的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!