Barring any complexity on your data, this should be achievable using a calculated field for ‘table1’ and ‘table2’. To get the desired format make sure to select ‘row’ as display type for pivot.
Please let me know if this helps and if it does please mark as solved.