MariaDB 10.3 解决掉了UPDATE不支持同一张表的子查询更新。
下面直接看案例
CREATE TABLE t1 (c1 INT, c2 INT);
INSERT INTO t1 VALUES (10,10), (20,20);
UPDATE t1 SET c1=c1+1 WHERE c2=(SELECT MAX(c2) FROM t1);
MySQL5.7 直接报错
MySQL 8.0 直接报错
MariaDB 10.3 更新成功
MySQL目前只能改写SQL实现,即max那条语句让其产生衍生表就可以通过。
UPDATE t1 a, (SELECT MAX(c2) as m_c2 FROM t1) as b SET a.c1=a.c1+1 WHERE a.c2=b.m_c2;
-----------------------------------------------------------------------------------------------
同理看下DELETE删除操作。
DROP TABLE t1;
CREATE TABLE t1 (c1 INT, c2 INT);
DELETE FROM t1 WHERE c1 IN (SELECT b.c1 FROM t1 b WHERE b.c2=0);
MySQL 8.0 直接报错
MariaDB 10.3 删除成功
参考:https://jira.mariadb.org/browse/MDEV-12137