mysql 查询出多条数据并更新其中一个字段值,不让更新怎么办
要更新语句:UPDATEtb_repair_basicSETtb_repair_basic.visitStatus='5'WHEREtb_repair_basic.idI...
要更新语句:UPDATE tb_repair_basic SET tb_repair_basic.visitStatus = '5' WHERE tb_repair_basic.id IN(
SELECT basic.id FROM tb_repair_mobileinfor mobileinfor, tb_repair_basic basic
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '') AND basic.customerName !='' AND basic.visitStatus= '2' AND mobileinfor.rbId = basic.id
)
先执行这个语句:
SELECT basic.id FROM tb_repair_mobileinfor mobileinfor, tb_repair_basic basic
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '') AND basic.customerName !='' AND basic.visitStatus= '2' AND mobileinfor.rbId = basic.id
结果:
合起来执行就报错:[Err] 1093 - You can't specify target table 'tb_repair_basic' for update in FROM clause 展开
SELECT basic.id FROM tb_repair_mobileinfor mobileinfor, tb_repair_basic basic
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '') AND basic.customerName !='' AND basic.visitStatus= '2' AND mobileinfor.rbId = basic.id
)
先执行这个语句:
SELECT basic.id FROM tb_repair_mobileinfor mobileinfor, tb_repair_basic basic
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '') AND basic.customerName !='' AND basic.visitStatus= '2' AND mobileinfor.rbId = basic.id
结果:
合起来执行就报错:[Err] 1093 - You can't specify target table 'tb_repair_basic' for update in FROM clause 展开
2个回答
展开全部
UPDATE tb_repair_basic SET tb_repair_basic.visitStatus = '5' WHERE tb_repair_basic.id IN(
SELECT mobileinfor.rbId FROM tb_repair_mobileinfor mobileinfor
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '')
) and tb_repair_basic.customerName !='' and tb_repair_basic.visitStatus= '2'
不能对同一个表tb_repair_basic 同时select和update
SELECT mobileinfor.rbId FROM tb_repair_mobileinfor mobileinfor
WHERE (mobileinfor.career IS NULL OR mobileinfor.career = '')
) and tb_repair_basic.customerName !='' and tb_repair_basic.visitStatus= '2'
不能对同一个表tb_repair_basic 同时select和update
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询