update mysql row (You can't specify target table 'x' for update in FROM clause)
sql语句(update/delete都会出现此问题) update x set available_material_id = null where id not in (select id from x where additional_info = 1); mistake 大致意思是,在同一语句中,不能先select出同一表中的某些值,再update这个表。 You can't specify target table 'x' for update in FROM clause mysql5.7解决办法 update x left join x xx on x.id = xx.id and xx.additional_info = 1 set available_material_id = null where xx.id is null; 老办法(有人说5.7已经不能用了) 原始: DELETE FROM tempA WHERE tid IN ( SELECT MAX(tid) AS tid FROM tempA GROUP BY name,age ) 改造后 DELETE FROM tempA WHERE tid NOT IN ( SELECT t.tid FROM ( SELECT MAX(tid) AS tid FROM tempA GROUP BY name,age