1. 程式人生 > >MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;

MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous

; SQL []; Column 'ID' in where clause is ambiguous; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous

意思是WHERE子句中的列“id”是不明確的

出現的原因是在多表連線查詢時,兩個表擁有一樣的欄位名,mysql不明確你要查詢的是哪個表的欄位名

錯誤程式碼:

<select id="getDiaryList" parameterType="Diary" resultMap="diaryMap">
        SELECT D.ID,D.TITLE,D.USER_ID,D.CREATED_DATE,D.CONTENT,D.STATUS,A.NICKNAME
        FROM diary D
        INNER JOIN ADMIN_USER A ON D.USER_ID=A.ID
        <where>
            <if test="id !=null">ID=#{id}</if>
            <if test="title !=null and title!=''">and TITLE like concat('%',#{title},'%')</if>
            <if test="nickname !=null and nickname!=''">and NICKNAME like concat('%',#{nickname},'%')</if>
        </where>
    </select>
正確程式碼:

將if條件中的ID前加上表名

<select id="getDiaryList" parameterType="Diary" resultMap="diaryMap">
        SELECT D.ID,D.TITLE,D.USER_ID,D.CREATED_DATE,D.CONTENT,D.STATUS,A.NICKNAME
        FROM diary D
        INNER JOIN ADMIN_USER A ON D.USER_ID=A.ID
        <where>
            <if test="id !=null">D.ID=#{id}</if>
            <if test="title !=null and title!=''">and TITLE like concat('%',#{title},'%')</if>
            <if test="nickname !=null and nickname!=''">and NICKNAME like concat('%',#{nickname},'%')</if>
        </where>
    </select>


相關推薦

MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous ;

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'ID' in where clause is ambiguous; SQL []; Colu

mybatis+mysql 關於兩個張表有相同屬性名查詢報錯的原因Column 'id' in order clause is ambiguous

mybatis+mysql 關於兩個張表有相同屬性名查詢會報錯的 注意,在MYSQL Wordbench中查詢時是可以通過的。 在mybatis中查詢兩張表中有相同屬性名會報錯 t_class表                                     

mysql Column 'dbvalue' in where clause is ambiguous解決方案

在一次使用mysql資料庫查詢的時候出現錯誤提示 Column 'languageid' in where clause is ambiguous,這個錯誤in where clause is amb

java開發常遇錯誤:Column 'AAA' in where clause is ambiguous解決辦法

當在java開發中遇到了Column ‘AAA’ in where clause is ambiguous問題時,你需要去看看:多表查詢的時候不同的表是否出現了相同名稱相同的列,如果存在,你需要在條件中或者查詢結果中指定表名比如:user表有name,post表

mybaits錯誤 MySQLIntegrityConstraintViolationException: Column 'name' in where clause is ambiguous

dispatch tin lse rep thread sta RoCE .data cti 五月 06, 2019 1:50:36 上午 org.apache.catalina.core.StandardWrapperValve invoke嚴重: Servlet.ser

mysql錯誤:Columnidin field list is ambiguous

原因:從join的表中進行select時,兩個表都有id屬性,列’ID’在欄位列表中重複,其實就是兩張表有相同的欄位,但是使用時表字段的名稱前沒有加表名,導致指代不明,前面加上字首“表名”就沒問題了。 SELECT a.* FROM d

連線查詢 Error:Column 'XXX' in order clause is ambiguous

錯誤為: Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'XXX' in order clause is ambiguous↵ ### T

mysql報錯:Column 'id' in field list is ambiguous,以及tp的三表聯合查詢語句,列印sql等

一、報錯資訊 1、報錯資訊       單純的根據報錯資訊,意思是在聯合查詢中,這幾個表的都有id值,mysql在執行查詢中,不能分辨id是屬於哪個表的。 解決方案: 1、修改表字段,不要都叫id (這個方案不好) 2、給表起別名 (我已經起了,所以

mybatis+mysql 關於兩個張表有相同屬性名查詢報錯的原因Column 'id' in order clause is ambiguous

mybatis+mysql 關於兩個張表有相同屬性名查詢會報錯的 注意,在MYSQL Wordbench中查詢時是可以通過的。 在mybatis中查詢兩張表中有相同屬性名會報錯 t_class表             

python操作資料庫出現錯誤 : Unknown column 'XXXX' in 'where clause'")錯誤

今天練習的時候,出現了這種坑爹的錯誤,找了好久,終於知道錯誤原因了,貼出修改的地方 在MySQL資料庫中存在中文的字元,python操作資料庫的語句如下 sql = "select * from t

MySql報錯原因分析Unknown column ‘xxx’ inwhere clause

在更新資料庫時曾經碰到過類似於Unknown column ‘xxx’ in ‘where clause’的問題。 單從字面理解,我們很容易得出列名不存在的結論,但是,很多時候起始並不是由於列名出

Unknown column 'rownum' in 'where clause'解決方案

Unknown column 'rownum' in 'where clause',當在巢狀的查詢語句裡面用到rownum的時候會遇到這個問題,比如: SELECT * FROM  (select t.id,t.name from USER_INFO t where t.s

TP 框架解決Unknown column 'XXX' in 'where clause' 問題

最近在使用TP框架開發公司網站,遇到了一個問題Unknown column 'XXX' in 'where clause'的問題。這個問題最初查詢使用者的個人資訊,分別通過使用者的手機號和郵箱查詢:1.手機號查詢$mobile = (string)'手機號XXX';$user

mysql下出現Unknown column 'id' in 'on clause'的解決方法

select vinfo.vid_id, vid_name, vid_leadrole, vid_desc, vid_director, vid_date,  vid_area, vid_pic, vid_score, vid_info, vinfo.cid, vid_ser

Sql語句錯誤 Unknown column xxx in where clause

Sql語句錯誤 但凡寫過sql語句的人估計都曾經碰到過類似於Unknown column ‘xxx’ in ‘where clause’的問題。 單從字面理解,我們很容易得出 列名不存在的結論,但是,很多時候起始並不是由於列名出錯造成的。而是由於拼湊sq

【MySQL 線上 BUG 分析】之 多表同欄位異常:Column ‘xxx’ in field list is ambiguous

一、生產出錯! 今天早上11點左右,我在工作休息之餘,擼了一下貓。突然,工作群響了,老大在裡面說:APP出錯了! 媽啊,這太嚇人了,因為只是說了出錯,但是沒說錯誤的資訊。所以我趕緊到APP上看看。 這果然是出錯了,而且還是簡單而粗暴的500,太嚇人了。 二、本地趕緊除錯起來! 既然線上出錯了,我們又不

解決mysql報錯:- Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ'

_for tran contains column schema mysql eat table express mysql執行報錯: - Expression #1 of ORDER BY clause is not in GROUP BY clause and cont

錯誤: nknown column 'xxxx' in 'where clause'

app ror -a col 相關 del dpa tid reflect nknown column ‘sdsds‘ in ‘where clause‘  運行環境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+

java.lang.Exception: 資源處理失敗,失敗原因:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column '?????‰' in 'where clause'

exception 替換 div name jdbc unknown syn lan -s 1:Unknown column ‘?????‰‘ in ‘where clause‘,這個問題,百度一搜,挺多的,但是貌似好像沒有解決我的問題。貼一下我是如何拼接sq

spring整合quartz異常:org.quartz.JobPersistenceException: Couldn't clean volatile data: Unknown column 'IS_VOLATILE' in 'where clause'

eat ola frame sch sched quartz dsc direct cde   自己的SSM項目中要用到定時器,初期使用Timer,後來用spring 的schedule,都比較簡單,所以功能比較單一。後來就研究quartz,準備整合到項目中。遇到了異