merges the 3 tables