create intermediate tables