返回顶部
首页 > 资讯 > 数据库 >update mysql row (You can't specify target table 'x' for update in FROM clause)
  • 509
分享到

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 wher&#

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
) t
)

查询的时候增加一层中间表,就可以避免该错误。

参考

https://stackoverflow.com/questions/51087937/on-update-mysql-row-you-cant-specify-target-table-x-for-update-in-from-claus
Https://blog.csdn.net/h996666/article/details/81699255
https://stackoverflow.com/questions/4429319/you-cant-specify-target-table-for-update-in-from-clause/14302701  
https://www.cnblogs.com/pcheng/p/4950383.html  
https://blog.csdn.net/poetssociety/article/details/82391523
您可能感兴趣的文档:

--结束END--

本文标题: update mysql row (You can't specify target table 'x' for update in FROM clause)

本文链接: https://lsjlt.com/news/3962.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作