Get different columns in MySQL
12:32 04 Sep 2015

Let's suppose that I have a table Table1(id INT, a text, b text, c text) and Table2(id INT, row0 text, row1 text, row2 text). I have some data on Table1 and I migrate it to Table2 (id->id, a->row0, b->row1, c->row2). Now, I want to check if all data is migrated and if the fields are all Ok. I use this select in order to find the Id values that are wrong, but I don't know an optimal way to find out which are the columns that are not ok, for example, I have the record Table1(1,hel,l,o) and the record Table2(1,he,null,o) I would like to know that the columns a/row0 and b/row1 are wrong

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
)
mysql comparison