620
620
drop table t1, t2;
621
#multi-delete with subselects
622
create table t11 (a int NOT NULL, b int, primary key (a));
623
create table t12 (a int NOT NULL, b int, primary key (a));
624
create temporary table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
625
insert into t11 values (0, 10),(1, 11),(2, 12);
626
insert into t12 values (33, 10),(22, 11),(2, 12);
627
insert into t2 values (1, 21),(2, 12),(3, 23);
638
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
639
ERROR HY000: You can't specify target table 't12' for update in FROM clause
640
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
641
ERROR 21000: Subquery returns more than 1 row
642
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
651
drop table t11, t12, t2;
652
621
#insert with subselects
653
622
CREATE TABLE t1 (x int);
654
623
create table t2 (a int);
1172
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
1173
CREATE TEMPORARY TABLE t2 (
1174
id int default NULL,
1175
name varchar(15) default NULL
1177
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
1178
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
1187
1136
# correct NULL in <CONSTANT> IN (SELECT ...)
1189
1138
create temporary table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;