[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月前
|
存储 关系型数据库 MySQL
Column Indexes
常见的索引类型通过复制列值至高效数据结构(如B树),实现快速查找。B树助力WHERE子句中=、>、≤、BETWEEN等运算符对应值的检索。每表至少支持16个索引,总长不少于256字节,具体限制依存储引擎而定。字符串列索引可指定前N字符,减少索引文件大小;BLOB或TEXT列索引需指定前缀长度。全文索引用于全文搜索,适用于InnoDB和MyISAM引擎的CHAR、VARCHAR、TEXT列;空间索引则针对空间数据类型,MyISAM和InnoDB采用R树索引。MEMORY引擎默认使用HASH索引,也支持BTREE索引。
|
9月前
|
SQL 关系型数据库 MySQL
Unknown column ‘xx’ in ‘on clause’
Unknown column ‘xx’ in ‘on clause’
56 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的解决办法
338 0
|
SQL 数据库
Unknown column ‘张三‘ in ‘where clause‘
Unknown column ‘张三‘ in ‘where clause‘
178 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
215 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
219 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
【已解决】SELECT list is not in GROUP BY clause and contains nonaggregated column
MySQL5.7.5后only_full_group_by成为sql_mode的默认选项之一,这可能导致一些sql语句失效。
520 0
|
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
476 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
350 0
【PHP报错集锦】Integrity constraint violation: 1052 Column 'vt_id' in where clause is ambiguous
成功解决TypeError: concat() got an unexpected keyword argument ‘join_axes‘
成功解决TypeError: concat() got an unexpected keyword argument ‘join_axes‘

热门文章

最新文章