Mysql:Error Code : 1093 You can't specify target table 'TDevice' for update in 转

<div class="iteye-blog-content-contain" style="font-size: 14px"></div>

 MYSQL executes the following statement and reports an error:

UPDATE `TDevice` SET `tracker_sim`='',`head_portrait`='',`mobile1`='',`mobile2`='',`mobile3`='',`nickname`='',`timezone`=0,`timezoneid`=31,`gps_interval`=NULL 

WHERE id IN ( SELECT a FROM ((SELECT id AS a FROM `TDevice` WHERE id NOT IN (SELECT t.did FROM `TDeviceUser` t LEFT JOIN `TDevice` d ON t.`did`=d.id) AND product_type=14)) AS temp)

 

The error message is as follows:

  错误代码: 1093
  You can't specify target table 'TDevice' for update in FROM clause

It means that the attribute value of the selected table tuple cannot be updated in the same statement

Solution: Just select the selected result through the intermediate table again.

UPDATE `TDevice` SET `tracker_sim`='',`head_portrait`='',`mobile1`='',`mobile2`='',`mobile3`='',`nickname`='',`timezone`=0,`timezoneid`=31,`gps_interval`=NULL 

WHERE id IN (SELECT id AS a FROM `TDevice` WHERE id NOT IN (SELECT t.did FROM `TDeviceUser` t LEFT JOIN `TDevice` d ON t.`did`=d.id) AND product_type=14)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326294920&siteId=291194637