Column ‘XXX(某字段)‘ in where clause is ambiguous
程序员文章站
2022-04-28 18:32:46
...
这个错误的意思:这个字段不明确
当在java开发中遇到了Column ‘XXX’ in where clause is ambiguous问题时,一般都是多表查询的问题,应该多表查询的时候两张表中字段有相同的,在where条件中那个字段没有明确是那张表的字段,这时你需要去xml语句报错字段明确是哪张表的就OK了。
比如:sys_user_role表有userCode ,sys_user 表有userCode ,而你想查询sys_user_role的userCode
<select id="selectAccompany" resultType="java.util.Map">
SELECT
sur.user_code "userCode",
su.user_name "userName",
su.mobile_phone "mobilePhone",
su.cert_no "certNo"
FROM sys_user_role sur INNER JOIN sys_user su on sur.user_code=su.user_code
<where>
AND role_code = 'HX_ZY_JL'
<if test="userRole.userCode != null">
AND sur.user_code = #{userRole.userCode,jdbcType=VARCHAR}
</if>
<if test="user.userName != null">
AND su.user_name = #{user.userName,jdbcType=VARCHAR}
</if>
</where>
</select>