I have two tables with the same structure. (refer below)
records = id (int, auto increment), name (varchar 250), age (int), address (varchar 250)
backup = id (int), name (varchar 250), age (int), address (varchar 250)
both table contents 3 records. Now, I want to compare those two tables per row by per column of the row and if there's a row that didnt match to the corresponding row on the compared table then produce and error.
table "records" content:
row 1 : column id = 1, column name = name1, column age = 12, column address = USA
row 2 : column id = 2, column name = name2, column age = 17, column address = USA
row 3 : column id = 3, column name = name3, column age = 32, column address = USA
table "backup" content:
row 1 : column id = 1, column name = name1change, column age = 12, column address = USA
row 2 : column id = 2, column name = name2, column age = 17, column address = USA
row 3 : column id = 3, column name = name3, column age = 32, column address = USA
as you can see from the above table contents, in the table "backup row 1, column name" there is a changes, name1 (records table) is changed to name1change (backup table). So when the row 1 of table records is compare to row 1 of table backup and found a difference, it will then get the row number and column name followed by a text of error (refer below)
echo $errorRow . "with" . $errorColumnOfTheErrorRow . "didn't match, there's is changes";
and I want to loop until the end of records with the same process (compare). How to make it? any ideas, help, suggestions and recommendation would be gladly appreciated. Thank you!
so far, what i tried is (refer below)
$sql = "SELECT DISTINCT * FROM (SELECT a.* FROM records a UNION SELECT b.* FROM backup b ) c";
$result = mysqli_query($this->db,$sql);
$sql = "SELECT COUNT(*), id FROM (SELECT DISTINCT * FROM (SELECT a.* FROM records a UNION SELECT b.* FROM backup b ) c ) d GROUP BY id;";
$result = mysqli_query($this->db,$sql);
echo $result;
as above query, im trying to display the unmatched row but sadly, not working.