mysql:You can't specify target table 'tb_student' for update in FROM clause

错误解释:
    大概意思是更新的字段在子查询中,导致报错,这时候加个中间吧就可以解决问题啦

错误示范:
    update msedu_student.tb_student  SET hk_mc_id = '',id_card = '',taiwan_id = '',hk_mc_id = '' where id in (select id  from msedu_student.tb_student where (hk_mc_id regexp '[^\x00-\xff]'||id_card regexp '[^\x00-\xff]' || passport regexp '[^\x00-\xff]' || taiwan_id regexp '[^\x00-\xff]'))
    
修改后示范

    UPDATE msedu_student.tb_student  SET hk_mc_id = '',id_card = '', taiwan_id = '',hk_mc_id = '' WHERE id IN (
    SELECT  id  FROM
    ( 
        SELECT id FROM msedu_student.tb_student WHERE ( hk_mc_id REGEXP '[^\x00-\xff]' || id_card REGEXP '[^\x00-\xff]' || passport REGEXP '[^\x00-\xff]' || taiwan_id REGEXP '[^\x00-\xff]')
    ) 
    as a
    ) 

猜你喜欢

转载自blog.csdn.net/weixin_34372728/article/details/87573519
今日推荐