为什么使用SELF-JOIN会给我错误?

时间:2019-03-19 11:21:16

标签: sql self-join

select 1.jmeno, 1.nadr
from zam as 1,
    zam as 2
where 1.nadr = 2.nadr
group by 1.jmeno, 1.nadr;

2 个答案:

答案 0 :(得分:0)

您需要更改表的别名

select a1.jmeno, a1.nadr
from zam as a1 join
    zam as a2
on a1.nadr = a2.nadr
group by a1.jmeno, a1.nadr

答案 1 :(得分:0)

以字母开头使用别名,并使用显式联接而不是逗号分隔的联接

select t1.jmeno, t1.nadr
from zam as t1 join  zam as t2
on t1.nadr = t2.nadr

因为您的查询中没有聚合,所以我删除了group by,改为可以使用distinct