用博客记录点滴……

用一张表里的记录更新自己(或另一张表)里的记录(exists使用)

update jqhdzt set shid=(select shid from v_plat_userjqinfo t where jqhdzt.jqbh=t.JQBH
 and jqhdzt.shid<>t.SHID  )
 where shid='0000010047'  and exists
 (select 1 from v_plat_userjqinfo t where jqhdzt.jqbh=t.JQBH
 and jqhdzt.shid<>t.SHID )

后面的

exists
 (select 1 from v_plat_userjqinfo t where jqhdzt.jqbh=t.JQBH
 and jqhdzt.shid<>t.SHID )  一定要加上,否则可能造成数据更新混乱。
posted @ 2017-01-12 13:03  aegisada  阅读(791)  评论(0编辑  收藏  举报