无法绑定多部分标识符(join sub query)

时间:2012-08-22 07:48:29

标签: sql tsql join

可能重复,但不提供此案例的见解: The multi-part identifier could not be bound

我查询了以下表格:

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

但我收到以下错误:

The multi-part identifier "l.id" could not be bound.

right join子查询有关。

奖励积分: 这是尝试根据单个列从inner join中删除重复的行。更好的方法吗?

2 个答案:

答案 0 :(得分:1)

试试这个,

SELECT l.id, l.foo, r.id, r.foo
FROM   storyevents l 
         INNER JOIN storyevents r 
               ON l.id = r.id
         RIGHT JOIN 
         (
               SELECT distinct extid, foo 
               FROM storyevents
         ) tmp on l.foo = tmp.foo AND
                  tmp.extid = l.id
where l.foo = 12345

答案 1 :(得分:0)

删除重复行的更好方法是什么?

 select distinct l.id, l.foo, r.id, r.foo 
 ....