Fix grouping of JOINs