You need to add the ds alias to the WHERE . ex, ds = date_sub('${DAY}',1) to e2.ds = date_sub('${DAY}',1) .
To clarify your problem a bit, here is a small example that shows the same behavior
CREATE EXTERNAL TABLE example (a INT, b INT) LOCATION '${OUTPUT}'; SELECT * FROM example e1 JOIN example e2 ON e1.a = e2.a WHERE b = 5;
This creates the same error:
FAILED: SemanticException Column b Found in more than One Tables/Subqueries
The problem is that column b exists both in example with an alias and in e1 and e2 . You and I might know that if you attach example to yourself by column a , then e1.b will be the same as e2.b , so it does not need an alias, but Hive does not know this, so you need to choose one to eliminate any ambiguity. It doesnβt matter if b section column or not.
source share