SQL查询报错:Not unique table/alias: 'ep' 问题求助
解决SQL报错「Not unique table/alias: 'ep'」的问题
错误原因
你写的SQL同时混用了旧版逗号分隔表和JOIN连接两种语法,还重复给同一个表定义了相同别名:
- 先是在FROM里用逗号列出了
endpoints ep、entitlement_types et、entitlement_values ev三张表 - 后面又用JOIN语句再次引入
endpoints ep和entitlement_types et,导致ep、et这两个别名被重复绑定,数据库无法识别到底对应哪次引用的表
修正后的SQL
SELECT ep.endpointname, ep.displayname, ep.description, et.Customproperty1_Label, ev.Customproperty1, et.Customproperty2_Label, ev.Customproperty2, et.Customproperty3_Label, ev.Customproperty3, et.Customproperty4_Label, ev.Customproperty4, et.Customproperty5_Label, ev.Customproperty5, et.Customproperty6_Label, ev.Customproperty6, et.Customproperty7_Label, ev.Customproperty7, et.Customproperty8_Label, ev.Customproperty8, et.Customproperty9_Label, ev.Customproperty9, et.Customproperty10_Label, ev.Customproperty10, et.Customproperty11_Label, ev.Customproperty11, et.Customproperty12_Label, ev.Customproperty12, et.Customproperty13_Label, ev.Customproperty13, et.Customproperty14_Label, ev.Customproperty14, et.Customproperty15_Label, ev.Customproperty15, et.Customproperty16_Label, ev.Customproperty16, et.Customproperty17_Label, ev.Customproperty17, et.Customproperty18_Label, ev.Customproperty18, et.Customproperty19_Label, ev.Customproperty19, et.Customproperty20_Label, ev.Customproperty20, et.Customproperty21_Label, ev.Customproperty21, et.Customproperty22_Label, ev.Customproperty22, et.Customproperty23_Label, ev.Customproperty23, et.Customproperty24_Label, ev.Customproperty24, et.Customproperty25_Label, ev.Customproperty25, et.Customproperty26_Label, ev.Customproperty26, et.Customproperty27_Label, ev.Customproperty27, et.Customproperty28_Label, ev.Customproperty28, et.Customproperty29_Label, ev.Customproperty29, et.Customproperty30_Label, ev.Customproperty30, et.Customproperty31_Label, ev.Customproperty31, et.Customproperty32_Label, ev.Customproperty32, et.Customproperty33_Label, ev.Customproperty33, et.Customproperty34_Label, ev.Customproperty34, et.Customproperty35_Label, ev.Customproperty35, et.Customproperty36_Label, ev.Customproperty36, et.Customproperty37_Label, ev.Customproperty37, et.Customproperty38_Label, ev.Customproperty38, et.Customproperty39_Label, ev.Customproperty39, et.Customproperty40_Label, ev.Customproperty40 FROM endpoints ep INNER JOIN entitlement_types et ON ep.endpointkey = et.endpointkey INNER JOIN entitlement_values ev ON et.entitlementtypekey = ev.entitlementtypekey
修正说明
- 统一使用标准的
INNER JOIN语法,从endpoints表开始依次关联另外两张表 - 每个表只定义一次别名,确保
ep、et、ev唯一对应各自的表 - 明确每个JOIN的连接条件,避免产生无意义的笛卡尔积
内容的提问来源于stack exchange,提问作者jessie.szprejda
相关产品推荐
相关产品推荐

