MySQL update with two subqueries

自闭症网瘾萝莉.ら 提交于 2019-12-02 09:59:53

Use:

UPDATE wtk_recur_subs_temp,
       final_bb, 
       wtk_recur_subs 
   SET wtk_recur_subs_temp.wtk_recur_date = final_bb.date
 WHERE final_bb.msisdn = wtk_recur_subs.wtk_recur_msisdn
   AND wtk_recur_subs_temp.wtk_recur_msisdn = final_bb.msisdn

The error is because:

SET wtk_recur_date = (SELECT final_bb.date
                        FROM final_bb, wtk_recur_subs 
                       WHERE final_bb.msisdn = wtk_recur_subs.wtk_recur_msisdn) 

...the final_bb.date value is all the date values where the final_bb and wtk_recur_subs msisdn column values match.

This may come as an utter shock to you, but one of your subqueries is returning more than one row!

This isn't permitted in the circumstance you've set up. Each of those two subqueries must return one and only one row. Or no rows.

Perform each subquery on it's own and determine which one is returning more than one row. If they shouldn't return more than one row, your data may be wrong. If they should return more than one row, you'll either want to modify the data so they don't (as I assume you expect), or add a LIMIT clause. Or add an aggregate function (like MAX) outside the query to do something proper with the multiple rows being returned.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!