mysql - sql subquery return more than 1 row
問題描述
update orders_father set ostatus=5,ofintimesys=now() where oid =(select oid from(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable);
這是代碼1。
update orders_father set ostatus=5,ofintimesys=now() where oid =any(select oid from(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable);
這是代碼2,在oid=后面增加了any
我的疑問是,為何代碼1會(huì)出現(xiàn)Error Code: 1242. Subquery returns more than 1 row這種錯(cuò)誤,而代碼2不會(huì)? 謝謝各位大神
背景:我是在存儲(chǔ)過程中使用的...
問題解答
回答1:where xxx = yyy的時(shí)候,右邊必須是單一的值,不能是多個(gè)值,而你第一個(gè)語句里面的
(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable)
會(huì)查出多個(gè)值,所以報(bào)Error Code: 1242. Subquery returns more than 1 row的錯(cuò)誤
解決的方法就是把where xxx = yyy變成where xxx in(yyy)或者where xxx = any yyy,這兩個(gè)表達(dá)是一個(gè)意思,不過any還可以其他的比較,比如where xxx > any yyy
回答2:any 相當(dāng) in()
相關(guān)文章:
1. windows誤人子弟啊2. 冒昧問一下,我這php代碼哪里出錯(cuò)了???3. MySQL主鍵沖突時(shí)的更新操作和替換操作在功能上有什么差別(如圖)4. python - linux怎么在每天的凌晨2點(diǎn)執(zhí)行一次這個(gè)log.py文件5. 數(shù)據(jù)庫 - Mysql的存儲(chǔ)過程真的是個(gè)坑!求助下面的存儲(chǔ)過程哪里錯(cuò)啦,實(shí)在是找不到哪里的問題了。6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. mysql優(yōu)化 - MySQL如何為配置表建立索引?8. 如何用筆記本上的apache做微信開發(fā)的服務(wù)器9. 我在網(wǎng)址中輸入localhost/abc.php顯示的是not found是為什么呢?10. 關(guān)于mysql聯(lián)合查詢一對多的顯示結(jié)果問題
