Fix errors when using multiple joins