我们可以通过合并从第一张表到第二张表以及从第二张表到第一张表的排除联接来获得表之间的差异。为了理解它,我们以以下两个表为例-
mysql> Select * from value1; +-----+-----+ | i | j | +-----+-----+ | 1 | 1 | | 2 | 2 | +-----+-----+ 2 rows in set (0.00 sec) mysql> Select * from value2; +------+------+ | i | j | +------+------+ | 1 | 1 | | 3 | 3 | +------+------+ 2 rows in set (0.00 sec)
现在,以下查询将执行表“ value1”和“ value2”之间的区别-
mysql> Select * from value1 left join value2 using(i,j) where value2.i is NULL UNION Select * from value2 left join value1 using(i,j) Where value1.i is NULL; +------+-----+ | i | j | +------+-----+ | 2 | 2 | | 3 | 3 | +-----+------+ 2 rows in set (0.07 sec)