fix join queries