Merging queries in table