1、先看错误的sql语句:
select a.authName from roles as r,authority as a,role_ah as ra where ra.roleId=r.roleId and ra.ahId=a.ahId and roleId='R002'
2、再看正确的sql语句:
select a.authName from roles as r,authority as a,role_ah as ra where ra.roleId=r.roleId and ra.ahId=a.ahId and r.roleId='R002'
[Err] 1052 - Column ‘roleId’ in where clause is ambiguous
这句话的意思是:[Err]1052-where子句中的“roleId”列不明确
多个表中都有相同的属性列(我这里是角色表、权限表、角色权限联合表。角色权限联合表中包含着角色表和权限表中的主键)。在查询时,没有指定哪个表的属性列。
总结:当遇到多表查询、并且查询条件的属性列存在多个表时、需要显示定义具体表的属性列。