我们可以通过联合排除连接从第一个表到第二个表以及从第二个表到第一个表来获得表之间的差异。为了理解它,我们以下面两个表为例 -
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)
以上是如何利用MySQL的连接来实现表之间的差异?的详细内容。更多信息请关注PHP中文网其他相关文章!