Even if they have different number of rows, just loop through the dataset that has less rows.
You can have the script run when either dataset1 or dataset2 changes.
Maybe even bind the difference dataset to the sql query.
SELECT ID, ABS(val1-val2)
FROM table
or
SELECT t1.ID, ABS(t1.val1 - t2.val2)
FROM table1 t1
JOIN table2 t2 ON t2.ID = t1.ID