假设我有一个表 Table1(id INT, a text, b text, c text) 和 Table2(id INT, row0 text, row1 text, row2 text)。我在 Table1 上有一些数据,并将其迁移到 Table2(id->id、a->row0、b->row1、c->row2)。现在,我想检查是否所有数据都已迁移以及字段是否全部正常。我使用此选择来查找错误的 Id 值,但我不知道一种最佳方法来找出哪些列不正确,例如,我有记录 Table1(1,hel,l ,o) 和记录 Table2(1,he,null,o) 我想知道列 a/row0 和 b/row1 是错误的
SELECT Table1.id, Table2.id FROM Table1 INNER JOIN Table2 ON Table1.id = Table2.id WHERE
Table1.a != Table2.row0 OR
(Table1.a NOT NULL AND BI_EN.contract.Table2.row0 IS NULL) OR
(Table1.a IS NULL AND BI_EN.contract.Table2.row0 IS NOT NULL) OR
Table1.b != Table2.row1 OR
(Table1.b NOT NULL AND BI_EN.contract.Table2.row1 IS NULL) OR
(Table1.b IS NULL AND BI_EN.contract.Table2.row1 IS NOT NULL) OR
Table1.c != Table2.row2 OR
(Table1.c NOT NULL AND BI_EN.contract.Table2.row2 IS NULL) OR
(Table1.c IS NULL AND BI_EN.contract.Table2.row2 IS NOT NULL)
最佳答案
我想这已经足够了:
SELECT Table1.id, Table1.a, Table1.b, Table1.c,
Table2.id, Table2.a, Table2.b, Table2.c
FROM Table1
INNER JOIN Table2
ON Table1.id = Table2.id
AND (Table1.a != Table2.row0
OR Table1.b != Table2.row1
OR Table1.c != Table2.row2 )
关于mysql - 获取MySQL中的不同列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32401753/