diff --git a/mindsdb_sql/planner/plan_join.py b/mindsdb_sql/planner/plan_join.py index 09bb983..bc4bd4a 100644 --- a/mindsdb_sql/planner/plan_join.py +++ b/mindsdb_sql/planner/plan_join.py @@ -481,6 +481,7 @@ def _check_conditions(node, **kwargs): conditions.append(node) elif table2 is not None: node.args = [arg1, arg2] + node = copy.deepcopy(node) data_conditions.append(node) query_traversal(fetch_table.join_condition, _check_conditions) @@ -501,12 +502,13 @@ def _check_conditions(node, **kwargs): # extract distinct values # remove alias - arg2 = Identifier(parts=[arg2.parts[-1]]) + arg2.parts = arg2.parts[-1:] query2 = Select(targets=[arg2], distinct=True) subselect_step = SubSelectStep(query2, fetch_step.result) subselect_step = self.add_plan_step(subselect_step) condition.args[1] = Parameter(subselect_step.result) + condition.op = 'in' conditions.append(condition) return conditions