1
drop table if exists t1,t2,t3;
2
drop database if exists mysqltest;
3
create table t1(id1 int not null auto_increment primary key, t char(12));
4
create table t2(id2 int not null, t char(12));
5
create table t3(id3 int not null, t char(12), index(id3));
6
select count(*) from t1 where id1 > 95;
9
select count(*) from t2 where id2 > 95;
12
select count(*) from t3 where id3 > 95;
15
update t1,t2,t3 set t1.t="aaa", t2.t="bbb", t3.t="cc" where t1.id1 = t2.id2 and t2.id2 = t3.id3 and t1.id1 > 90;
16
select count(*) from t1 where t = "aaa";
19
select count(*) from t1 where id1 > 90;
22
select count(*) from t2 where t = "bbb";
25
select count(*) from t2 where id2 > 90;
28
select count(*) from t3 where t = "cc";
31
select count(*) from t3 where id3 > 90;
34
delete t1.*, t2.*, t3.* from t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3 and t1.id1 > 95;
35
check table t1, t2, t3;
36
Table Op Msg_type Msg_text
37
test.t1 check status OK
38
test.t2 check status OK
39
test.t3 check status OK
40
select count(*) from t1 where id1 > 95;
43
select count(*) from t2 where id2 > 95;
46
select count(*) from t3 where id3 > 95;
49
delete t1, t2, t3 from t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3 and t1.id1 > 5;
50
select count(*) from t1 where id1 > 5;
53
select count(*) from t2 where id2 > 5;
56
select count(*) from t3 where id3 > 5;
59
delete from t1, t2, t3 using t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3 and t1.id1 > 0;
60
select count(*) from t1 where id1;
63
select count(*) from t2 where id2;
66
select count(*) from t3 where id3;
70
create table t1(id1 int not null primary key, t varchar(100)) pack_keys = 1;
71
create table t2(id2 int not null, t varchar(100), index(id2)) pack_keys = 1;
72
delete t1 from t1,t2 where t1.id1 = t2.id2 and t1.id1 > 500;
75
id int NOT NULL default '0',
76
name varchar(10) default NULL,
79
INSERT INTO t1 VALUES (1,'aaa'),(2,'aaa'),(3,'aaa');
81
id int NOT NULL default '0',
82
name varchar(10) default NULL,
85
INSERT INTO t2 VALUES (2,'bbb'),(3,'bbb'),(4,'bbb');
87
id int NOT NULL default '0',
88
mydate datetime default NULL,
91
INSERT INTO t3 VALUES (1,'2002-02-04 00:00:00'),(3,'2002-05-12 00:00:00'),(5,'2002-05-12 00:00:00'),(6,'2002-06-22
92
00:00:00'),(7,'2002-07-22 00:00:00');
93
delete t1,t2,t3 from t1,t2,t3 where to_days(now())-to_days(t3.mydate)>=30 and t3.id=t1.id and t3.id=t2.id;
101
CREATE TABLE IF NOT EXISTS `t1` (
102
`id` int NOT NULL auto_increment,
107
CREATE TABLE IF NOT EXISTS `t2` (
108
`ID` int NOT NULL auto_increment,
109
`ParId` int default NULL,
113
KEY `IX_ParId_t2` (`ParId`),
114
FOREIGN KEY (`ParId`) REFERENCES `t1` (`id`)
116
INSERT INTO t1(tst,tst1) VALUES("MySQL","MySQL AB"), ("MSSQL","Microsoft"), ("ORACLE","ORACLE");
117
INSERT INTO t2(ParId) VALUES(1), (2), (3);
123
UPDATE t2, t1 SET t2.tst = t1.tst, t2.tst1 = t1.tst1 WHERE t2.ParId = t1.Id;
130
create table t1 (n numeric(10));
131
create table t2 (n numeric(10));
132
insert into t2 values (1),(2),(4),(8),(16),(32);
133
select * from t2 left outer join t1 using (n);
141
delete t1,t2 from t2 left outer join t1 using (n);
142
select * from t2 left outer join t1 using (n);
145
create table t1 (n int not null primary key, d int);
146
create table t2 (n int not null primary key, d int);
147
insert into t1 values(1,1);
148
insert into t2 values(1,10),(2,20);
149
LOCK TABLES t1 write, t2 read;
150
DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n;
151
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
152
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
153
ERROR HY000: Table 't2' was locked with a READ lock and can't be updated
154
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
156
LOCK TABLES t1 write, t2 write;
157
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
161
DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n;
169
set sql_safe_updates=1;
170
create table t1 (n int, d int);
171
create table t2 (n int, d int);
172
insert into t1 values(1,1);
173
insert into t2 values(1,10),(2,20);
174
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
175
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
176
set sql_safe_updates=0;
178
set timestamp=1038401397;
179
create table t1 (n int not null primary key, d int, t timestamp);
180
create table t2 (n int not null primary key, d int, t timestamp);
181
insert into t1 values(1,1,NULL);
182
insert into t2 values(1,10,NULL),(2,20,NULL);
183
set timestamp=1038000000;
184
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
185
select n,d,unix_timestamp(t) from t1;
186
n d unix_timestamp(t)
188
select n,d,unix_timestamp(t) from t2;
189
n d unix_timestamp(t)
192
UPDATE t1,t2 SET 1=2 WHERE t1.n=t2.n;
193
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near '1=2 WHERE t1.n=t2.n' at line 1
196
set sql_safe_updates=0;
197
create table t1 (n int not null primary key, d int);
198
create table t2 (n int not null primary key, d int);
199
insert into t1 values(1,1), (3,3);
200
insert into t2 values(1,10),(2,20);
201
UPDATE t2 left outer join t1 on t1.n=t2.n SET t1.d=t2.d;
211
create table t1 (n int, d int);
212
create table t2 (n int, d int);
213
insert into t1 values(1,1),(1,2);
214
insert into t2 values(1,10),(2,20);
215
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
225
create table t1 (n int, d int);
226
create table t2 (n int, d int);
227
insert into t1 values(1,1),(3,2);
228
insert into t2 values(1,10),(1,20);
229
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
238
UPDATE t1 a ,t2 b SET a.d=b.d,b.d=30 WHERE a.n=b.n;
247
DELETE a, b FROM t1 a,t2 b where a.n=b.n;
254
CREATE TABLE t1 ( broj int NOT NULL default '0', naziv char(25) NOT NULL default 'NEPOZNAT', PRIMARY KEY (broj)) ENGINE=MyISAM;
255
INSERT INTO t1 VALUES (1,'jedan'),(2,'dva'),(3,'tri'),(4,'xxxxxxxxxx'),(5,'a'),(10,''),(11,''),(12,''),(13,'');
256
CREATE TABLE t2 ( broj int NOT NULL default '0', naziv char(25) NOT NULL default 'NEPOZNAT', PRIMARY KEY (broj)) ENGINE=MyISAM;
257
INSERT INTO t2 VALUES (1,'jedan'),(2,'dva'),(3,'tri'),(4,'xxxxxxxxxx'),(5,'a');
258
CREATE TABLE t3 ( broj int NOT NULL default '0', naziv char(25) NOT NULL default 'NEPOZNAT', PRIMARY KEY (broj)) ENGINE=MyISAM;
259
INSERT INTO t3 VALUES (1,'jedan'),(2,'dva');
260
update t1,t2 set t1.naziv="aaaa" where t1.broj=t2.broj;
261
update t1,t2,t3 set t1.naziv="bbbb", t2.naziv="aaaa" where t1.broj=t2.broj and t2.broj=t3.broj;
263
CREATE TABLE t1 (a int not null primary key, b int not null, key (b));
264
CREATE TABLE t2 (a int not null primary key, b int not null, key (b));
265
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
266
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
267
update t1,t2 set t1.a=t1.a+100;
279
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
291
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
303
update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t2.a=t1.a-100;
326
update t1,t2 set t1.b=t2.b, t1.a=t2.a where t1.a=t2.a and not exists (select * from t2 where t2.a > 10);
328
CREATE TABLE t3 ( KEY1 varchar(50) NOT NULL default '', PARAM_CORR_DISTANCE_RUSH double default NULL, PARAM_CORR_DISTANCE_GEM double default NULL, PARAM_AVG_TARE double default NULL, PARAM_AVG_NB_DAYS double default NULL, PARAM_DEFAULT_PROP_GEM_SRVC varchar(50) default NULL, PARAM_DEFAULT_PROP_GEM_NO_ETIK varchar(50) default NULL, PARAM_SCENARIO_COSTS varchar(50) default NULL, PARAM_DEFAULT_WAGON_COST double default NULL, tmp int default NULL, PRIMARY KEY (KEY1)) ENGINE=MyISAM;
329
INSERT INTO t3 VALUES ('A',1,1,22,3.2,'R','R','BASE2',0.24,NULL);
330
create table t1 (A varchar(1));
331
insert into t1 values ("A") ,("B"),("C"),("D");
332
create table t2(Z varchar(15));
333
insert into t2(Z) select concat(a.a,b.a,c.a,d.a) from t1 as a, t1 as b, t1 as c, t1 as d;
334
update t2,t3 set Z =param_scenario_costs;
336
create table t1 (a int, b int);
337
create table t2 (a int, b int);
338
insert into t1 values (1,1),(2,1),(3,1);
339
insert into t2 values (1,1), (3,1);
340
update t1 left join t2 on t1.a=t2.a set t1.b=2, t2.b=2 where t1.b=1 and t2.b=1 or t2.a is NULL;
341
select t1.a, t1.b,t2.a, t2.b from t1 left join t2 on t1.a=t2.a where t1.b=1 and t2.b=1 or t2.a is NULL;
345
create table t1 (a int not null auto_increment primary key, b int not null);
346
insert into t1 (b) values (1),(2),(3),(4);
347
update t1, t1 as t2 set t1.b=t2.b+1 where t1.a=t2.a;
355
create table t1(id1 int, field char(5));
356
create table t2(id2 int, field char(5));
357
insert into t1 values (1, 'a'), (2, 'aa');
358
insert into t2 values (1, 'b'), (2, 'bb');
367
update t2 inner join t1 on t1.id1=t2.id2
368
set t2.field=t1.field
370
update t2, t1 set t2.field=t1.field
371
where t1.id1=t2.id2 and 0=1;
372
delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2
374
delete t1, t2 from t2,t1
375
where t1.id1=t2.id2 and 0=1;
377
create table t1 ( a int not null, b int not null) ;
378
alter table t1 add index i1(a);
379
delete from t1 where a > 2000000;
380
create table t2 like t1;
381
insert into t2 select * from t1;
382
select 't2 rows before small delete', count(*) from t1;
383
t2 rows before small delete count(*)
384
t2 rows before small delete 2000000
385
delete t1,t2 from t1,t2 where t1.b=t2.a and t1.a < 2;
386
select 't2 rows after small delete', count(*) from t2;
387
t2 rows after small delete count(*)
388
t2 rows after small delete 1999999
389
select 't1 rows after small delete', count(*) from t1;
390
t1 rows after small delete count(*)
391
t1 rows after small delete 1999999
392
delete t1,t2 from t1,t2 where t1.b=t2.a and t1.a < 100*1000;
393
select 't2 rows after big delete', count(*) from t2;
394
t2 rows after big delete count(*)
395
t2 rows after big delete 1900001
396
select 't1 rows after big delete', count(*) from t1;
397
t1 rows after big delete count(*)
398
t1 rows after big delete 1900001
400
CREATE TABLE t1 ( a int );
401
CREATE TABLE t2 ( a int );
402
DELETE t1 FROM t1, t2 AS t3;
403
DELETE t4 FROM t1, t1 AS t4;
404
DELETE t3 FROM t1 AS t3, t1 AS t4;
405
DELETE t1 FROM t1 AS t3, t2 AS t4;
406
ERROR 42S02: Unknown table 't1' in MULTI DELETE
407
INSERT INTO t1 values (1),(2);
408
INSERT INTO t2 values (1),(2);
409
DELETE t1 FROM t1 AS t2, t2 AS t1 where t1.a=t2.a and t1.a=1;
417
DELETE t2 FROM t1 AS t2, t2 AS t1 where t1.a=t2.a and t1.a=2;
425
create table `t1` (`p_id` int NOT NULL auto_increment, `p_code` varchar(20) NOT NULL default '', `p_active` int NOT NULL default '1', PRIMARY KEY (`p_id`) );
426
create table `t2` (`c2_id` int NULL auto_increment, `c2_p_id` int NOT NULL default '0', `c2_note` text NOT NULL, `c2_active` int NOT NULL default '1', PRIMARY KEY (`c2_id`), KEY `c2_p_id` (`c2_p_id`) );
427
insert into t1 values (0,'A01-Comp',1);
428
insert into t1 values (0,'B01-Comp',1);
429
insert into t2 values (0,1,'A Note',1);
430
update t1 left join t2 on p_id = c2_p_id set c2_note = 'asdf-1' where p_id = 2;
436
c2_id c2_p_id c2_note c2_active
439
create table t1 (a int, primary key (a));
440
create table t2 (a int, primary key (a));
441
create table t3 (a int, primary key (a));
442
delete t1,t3 from t1,t2 where t1.a=t2.a and t2.a=(select t3.a from t3 where t1.a=t3.a);
443
ERROR 42S02: Unknown table 't3' in MULTI DELETE
444
drop table t1, t2, t3;
445
create table t1 (col1 int);
446
create table t2 (col1 int);
447
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
448
ERROR HY000: You can't specify target table 't1' for update in FROM clause
449
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
450
ERROR HY000: You can't specify target table 't1' for update in FROM clause
453
aclid bigint not null primary key,
457
refid bigint not null primary key,
458
aclid bigint, index idx_acl(aclid)
460
insert into t2 values(1,null);
461
delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1';
463
create table t1(a int);
464
create table t2(a int);
465
delete from t1,t2 using t1,t2 where t1.a=(select a from t1);
466
ERROR HY000: You can't specify target table 't1' for update in FROM clause
468
create table t1 ( c char(8) not null ) engine=innodb;
469
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
470
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
471
alter table t1 add b char(8) not null;
472
alter table t1 add a char(8) not null;
473
alter table t1 add primary key (a,b,c);
474
update t1 set a=c, b=c;
475
create table t2 like t1;
476
insert into t2 select * from t1;
477
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
479
create table t1 ( c char(8) not null ) engine=innodb;
480
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
481
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
482
alter table t1 add b char(8) not null;
483
alter table t1 add a char(8) not null;
484
alter table t1 add primary key (a,b,c);
485
update t1 set a=c, b=c;
486
create table t2 like t1;
487
insert into t2 select * from t1;
488
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
490
create table t1 (a int, b int);
491
insert into t1 values (1, 2), (2, 3), (3, 4);
492
create table t2 (a int);
493
insert into t2 values (10), (20), (30);
494
create table v1 as select a as b, a/10 as a from t2;
496
alter table t1 add column c int default 100 after a;
497
update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
511
create table t1 (i1 int, i2 int, i3 int);
512
create table t2 (id int, c1 varchar(20), c2 varchar(20));
513
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
514
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
515
select * from t1 order by i1;
527
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
528
select * from t1 order by i1;
535
select * from t2 order by id;
540
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
541
select * from t1 order by i1;
546
select * from t2 order by id;
551
create table t1 (i1 int auto_increment not null, i2 int, i3 int, primary key (i1));
552
create table t2 (id int auto_increment not null, c1 varchar(20), c2 varchar(20), primary key(id));
553
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
554
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
555
select * from t1 order by i1;
562
select * from t2 order by id;
567
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
568
select * from t1 order by i1;
575
select * from t2 order by id;
580
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
581
select * from t1 order by i1;
586
select * from t2 order by id;