MySQL Not in specified twice, both as a target for ‘UPDATE’ and as a separate source for data

MySQL Not in specified twice, both as a target for ‘UPDATE’ and as a separate source for data

Thursday, December 10, 2020

11:56 AM

 

出错:

 
 

update tb_delivery_order

set status_code = ‘NEW’

where order_number = ‘DN0000000001’

and id not in (select id

from tb_delivery_order

where order_number = ‘DN0000000001’

and item_no <> 1

and qc_flag = true )        

 
 

Error Code: 1093. Table ‘tb_delivery_order’ is specified twice, both as a target for ‘UPDATE’ and as a separate source for data        0.000 sec

 
 

 
 

 
 

调整后:

 
 

update tb_delivery_order

set status_code = ‘NEW’

where order_number = ‘DN0000000001’

and id not in (select a.id from

(select id

from tb_delivery_order

where order_number = ‘DN0000000001’

and item_no <> 1

and qc_flag = true)a )

;

Leave a Comment