[Err] 1052 - Column ‘roleId‘ in where clause is ambiguous

简介: 这篇文章解释了SQL查询中出现"Column ‘roleId’ in where clause is ambiguous"错误的原因,即在多表查询中,如果没有明确指定表名,相同的列名在where子句中会产生歧义,并提供了修正方法,即明确指定条件中所引用的列属于哪个表。

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”列不明确

多个表中都有相同的属性列(我这里是角色表、权限表、角色权限联合表。角色权限联合表中包含着角色表和权限表中的主键)。在查询时,没有指定哪个表的属性列。

总结:当遇到多表查询、并且查询条件的属性列存在多个表时、需要显示定义具体表的属性列。

相关文章
|
5月前
|
JSON Java 数据格式
UnrecognizedPropertyException: Unrecognized field 解决
UnrecognizedPropertyException: Unrecognized field 解决
203 0
|
7月前
|
SQL 关系型数据库 MySQL
Unknown column ‘xx’ in ‘on clause’
Unknown column ‘xx’ in ‘on clause’
52 0
|
存储 SQL 关系型数据库
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column的解决办法
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column的解决办法
254 0
|
关系型数据库 MySQL 数据库
View ‘information_schema.SCHEMATA‘ references invalid table(s) or column(s) or function(s) or define
View ‘information_schema.SCHEMATA‘ references invalid table(s) or column(s) or function(s) or define
250 0
|
SQL 数据库
Unknown column ‘张三‘ in ‘where clause‘
Unknown column ‘张三‘ in ‘where clause‘
161 0
|
数据库
Incorrect table definition; there can be only one auto column and it must be defined as a key
Incorrect table definition; there can be only one auto column and it must be defined as a key
185 0
Incorrect table definition; there can be only one auto column and it must be defined as a key
1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause
1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause
210 0
1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause
|
SQL 关系型数据库 MySQL
报错:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregat
报错:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregat
432 0
报错:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregat
|
PHP
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
339 0
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
|
SQL 关系型数据库 MySQL
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】
747 0
[Err] 1294 - Invalid ON UPDATE clause for 'comment_time' column【详细解决办法】