mysql报错You can't specify target table 'b' for update in FROM clause
来源:互联网 发布:心事谁人知闽南语翻译 编辑:程序博客网 时间:2024/06/05 22:56
mysql使用update
UPDATE zt_project b SET b.deleted
=’1’ WHERE b.id
IN
(SELECT p.id FROM zt_projectproduct pp, zt_project p WHERE pp.product IN (20) AND p.id = pp.project AND p.deleted = ‘0’)
报错:
You can’t specify target table ‘b’ for update in FROM clause
原因分析:
mysql不能先select出同一表中的某些值,再update/delete这个表(在同一语句中)。oracle不会出现此问题。
解决方案一:
UPDATE zt_project b SET b.deleted
=’1’ WHERE b.id
IN (SELECT id FROM
(SELECT p.id FROM zt_projectproduct pp, zt_project p WHERE pp.product IN (20) AND p.id = pp.project AND p.deleted = ‘0’) tmp)
将查询结果塞在临时表中
解决方案二:
CREATE TABLE tmp AS SELECT MIN(id) AS col1 FROM blur_article GROUP BY title;
DELETE FROM blur_article WHERE id NOT IN (SELECT col1 FROM tmp);
DROP TABLE tmp;
新建临时表,存储数据,用完后删除。
- mysql报错You can't specify target table 'b' for update in FROM clause
- MySql报错: You can't specify target table 'table name' for update in FROM clause
- MySQL报错“ you can't specify the target table for ‘update’ in from clause”
- MySQL 修改报错 You can't specify target table 'tb_trade' for update in FROM clause
- MySql报错: You can't specify target table 'table name' for update in FROM clause解决办法
- mysql中update ..where 字段 in(..) 报You can't specify target table for update in FROM clause错误
- mysql update语句问题:You can't specify target table 'user' for update in FROM clause
- 【MySQL】1093 You can't specify target table 'table name' for update in FROM clause
- ERROR 1093 (HY000): You can't specify target table 'b' for update in FROM clause
- Mysql - You can't specify target table 'dataproduct' for update in FROM clause
- mysql中You can't specify target table for update in FROM clause错误
- MYSQL 临时表 #1093 - You can't specify target table 'dealer_admin' for update in FROM clause
- MySQL "You can't specify target table 'X' for update in FROM clause" 错误解决方法
- Mysql 错误 Code: 1093. You can't specify target table for update in FROM clause
- mysql中You can't specify target table for update in FROM clause错误
- mysql问题:You can't specify target table for update in FROM clause
- mysql中You can't specify target table for update in FROM clause错误
- MYSQL 1093 - You can't specify target table '' for update in FROM clause
- Huffman代码调试
- Referenced file contains errors (http://mybatis.org/dtd/mybatis-3-mapper.dtd)报错处理
- Fragment切换
- systemctl 针对 service 类型的配置文件
- 计算机视觉牛人博客和代码汇总
- mysql报错You can't specify target table 'b' for update in FROM clause
- ARP协议和ARP脚本抓取MAC地址
- LeetCode 10. Regular Expression Matching
- Linux进程间通信
- 中断处理特权级转换
- Codeforces 327E Axis Walking【状压Dp+Lowbit优化】
- 获取所有已安装的应用
- Mac显示隐藏文件夹
- C语言 高速公路超速处罚