summaryrefslogtreecommitdiff
path: root/mysql-test/t/insert_select.test
blob: 625f4755a79118fdebaaf55e56bbdfb59e8fd40f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# Problem with INSERT ... SELECT
#

drop table if exists t1,t2;
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
create table t2 (payoutID SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
select * from t2;
drop table t1,t2;

#
# Another problem from Bug #2012
#

CREATE TABLE t1(
 Month date NOT NULL,
 Type tinyint(3) unsigned NOT NULL auto_increment,
 Field int(10) unsigned NOT NULL,
 Count int(10) unsigned NOT NULL,
 UNIQUE KEY Month (Month,Type,Field)
);
	  
insert into t1 Values
(20030901, 1, 1, 100),
(20030901, 1, 2, 100),
(20030901, 2, 1, 100),
(20030901, 2, 2, 100),
(20030901, 3, 1, 100);

select * from t1;
	  
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
	  
create table t2(No int not null, Field int not null, Count int not null);
	  
insert into t2 Select null, Field, Count From t1 Where Month=20030901 and Type=2;
	  
select * from t2;

drop table t1, t2;