SELECT @sum:=SUM(`int1` + `int1_key` + `int1_unique` + `int2` + `int2_key` + `int2_unique`) AS TotalSum FROM t1; # Get some diagnostics if sum is non-zero if (`SELECT @sum`) { # Get sum of consistent rows (should be 0) SELECT SUM(`int1` + `int1_key` + `int1_unique` + `int2` + `int2_key` + `int2_unique`) FROM t1 where `is_consistent` = 1; # Get sum of inconsistent rows (should be non-0 if the total sum is to be non-0) SELECT SUM(`int1` + `int1_key` + `int1_unique` + `int2` + `int2_key` + `int2_unique`) FROM t1 where `is_consistent` = 0; # Get number of inconsistent rows SELECT COUNT(*) FROM t1 WHERE `is_consistent` = 0; # See if there is a single row which is the culprit SELECT * FROM t1 WHERE `int1` + `int1_key` + `int1_unique` + `int2` + `int2_key` + `int2_unique` = @sum; SELECT * FROM t1 WHERE `int1` + `int1_key` + `int1_unique` + `int2` + `int2_key` + `int2_unique` = -@sum; }