Enclose an example of these two tables and the expected result, it will be easier to create a solution.