mysql - sql subquery return more than 1 row
伊谢尔伦
伊谢尔伦 2017-04-17 15:29:52
0
2
629
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不会? 谢谢各位大神

背景:我是在存储过程中使用的...

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回覆(2)
黄舟

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

左手右手慢动作

any 相當 in()

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!