在MySQL中获取两个记录表之间的区别

时间:2017-07-21 16:30:18

标签: mysql

我在MySQL中运行两个记录表之间的区别。不幸的是,它没有返回所有差异记录,

SELECT * FROM A. WHERE(部门,EmpNum)不在(SELECT部门,EmpNum FROM B)

这将返回EmpNum对A唯一的所有记录,但它不会返回A中不存在EmpNum AND Dept的所有记录。

例如,在A中,以下记录未显示在B中,但未返回0451,1234 A
Dept EmpNum
0450 1234 0451 1234 0452 1235

SELECT 'robot' AS set, r.* FROM employee_status_ext r WHERE ROW(r.EmpNum, r.Dept) NOT IN ( SELECT EmpNum, Dept FROM employee_status_ext_archive ) UNION ALL SELECT 'employee_status_ext_archive' AS set, t.* FROM employee_status_ext_archive t WHERE ROW(t.EmpNum, t.Dept) NOT IN ( SELECT EmpNum, Dept FROM employee_status_ext )

0 个答案:

没有答案