Possible duplicate, but providing no insight to this case: The multi-part identifier could not be bound
I have a query of the following form:
select l.id, l.foo, r.id, r.foo
from tbl l
inner join storyevents r on l.id = r.id
right join (
select distinct foo from tbl where id= l.id
) tmp on l.foo = tmp.foo
where l.foo = 12345
But i get the following error:
The multi-part identifier "l.id" could not be bound.
in relation to the right join
sub query.
Bonus points:
This is an attempt to remove duplicate rows from the inner join
based on a single column. Better way to do this?