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會出現Error Code: 1242. Subquery returns more than 1 row這種錯誤,而代碼2不會? 謝謝各位大神
背景:我是在存儲過程中使用的...
問題解答
回答1:where xxx = yyy的時候,右邊必須是單一的值,不能是多個值,而你第一個語句里面的
(SELECT oid FROM orders_father where TIMESTAMPDIFF(HOUR,odlvtime,now())>parameter and ostatus=4)as tempTable)
會查出多個值,所以報Error Code: 1242. Subquery returns more than 1 row的錯誤
解決的方法就是把where xxx = yyy變成where xxx in(yyy)或者where xxx = any yyy,這兩個表達是一個意思,不過any還可以其他的比較,比如where xxx > any yyy
回答2:any 相當 in()
相關文章:
1. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?2. mysql - 把一個表中的數據count更新到另一個表里?3. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?4. python - 爬蟲模擬登錄后,爬取csdn后臺文章列表遇到的問題5. visual-studio - Python OpenCV: 奇怪的自動補全問題6. linux - Ubuntu下編譯Vim8(+python)無數次編譯失敗7. node.js - nodejs開發中常用的連接mysql的庫8. mysql 查詢身份證號字段值有效的數據9. 視頻文件不能播放,怎么辦?10. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處
