我哈瓦一個更新SQL象下面這樣:奇怪的事情與IF在SQL
update saletargets_import_data as st_im left join saletargets as st
on st_im.saletarget_hospital_id=st.saletarget_hospital_id
and st_im.saletarget_product_id=st.saletarget_product_id
set st_im.record_id=if(st.deleted=0 and st.id is not null,st.id,st_im.record_id)
where st_im.import_id=383;
它不affect.which回報: 0行(S)受影響的行匹配:1:0的警告:0 和st_im.record_id不更新
然而,當我使用如下:
update saletargets_import_data as st_im left join saletargets as st
on st_im.saletarget_hospital_id=st.saletarget_hospital_id
and st_im.saletarget_product_id=st.saletarget_product_id
set st_im.record_id=if(st.id is not null,st.id,st_im.record_id)
where st_im.import_id=383 and st.deleted=0;
它的工作原理,在st_im.record_id更新!但我不知道爲什麼... Clould任何人都可以看出這兩個SQL之間的區別嗎?
對於未來搜索的人,請澄清一下,如果是[tag:mysql]或者微軟[tag:sql-server] – mendosi