這篇文章主要介紹了MySQL錯誤Subquery returns more than 1 row怎么解決的相關(guān)知識,內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇mysql錯誤Subquery returns more than 1 row怎么解決文章都會有所收獲,下面我們一起來看看吧。
10年積累的網(wǎng)站設(shè)計、網(wǎng)站制作經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先制作網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有富川免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
mysql報錯:SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row
錯誤的意思是指子查詢結(jié)果多于一行。
以這個sql語句為例
select * from table1 where table1.colums=(select columns from table2);
1)如果是寫入重復(fù),去掉重復(fù)數(shù)據(jù)。然后寫入的時候,可以加邏輯判斷(php)或者外鍵(mysql),防止數(shù)據(jù)重復(fù)寫入。
(我實際開發(fā)中遇到的就是數(shù)據(jù)重復(fù)寫入的情況,在數(shù)據(jù)庫查到有相同的數(shù)據(jù)兩條,這不符原本的原本的業(yè)務(wù)需求)
2)在子查詢條件語句加limit 1,找到一個符合條件的就可以了
select * from table1 where table1.colums=(select columns from table2 limit 1);
3)在子查詢前加any關(guān)鍵字
select * from table1 where table1.colums=any(select columns from table2);
1 queries executed, 0 success, 1 errors, 0 warnings
查詢:SELECT t.id, DATE_FORMAT( t.statisTime, '%Y-%m-%d %H:%i:%s' ) statisTime, (SELECT `id` FROM t_truck_info WHERE id = t.plateId...
錯誤代碼: 1242Subquery returns more than 1 row
執(zhí)行耗時 : 0.009 sec傳送時間 : 0.002 sec總耗時 : 0.012 sec
在編寫查詢SQL語句時,其中有個字段是從另一張表里獲取
select t.id,(select num from t_user_info where id = stuNo) as amount from t_stu_info t left join t_user_info t0 on t0.id = t.stuNo
查詢出num是多條數(shù)據(jù),而外層查詢結(jié)果是要求num為一條數(shù)據(jù)
select t.id,(select sum(num) from t_user_info where id = stuNo) as amount from t_stu_info t left join t_user_info t0 on t0.id = t.stuNo
關(guān)于“mysql錯誤Subquery returns more than 1 row怎么解決”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對“mysql錯誤Subquery returns more than 1 row怎么解決”知識都有一定的了解,大家如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享名稱:mysql錯誤Subquery?returns?more?than?1?row怎么解決
URL標(biāo)題:http://chinadenli.net/article32/joidpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站、微信公眾號、商城網(wǎng)站、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)