10
10
grp int default NULL,
11
a bigint default NULL,
11
a bigint unsigned default NULL,
12
12
c char(10) NOT NULL default ''
14
14
INSERT INTO t1 VALUES (1,1,'a'),(2,2,'b'),(2,3,'c'),(3,4,'E'),(3,5,'C'),(3,6,'D'),(NULL,NULL,'');
15
create table t2 (id int, a bigint not null, c char(10), d int, primary key (a));
15
create table t2 (id int, a bigint unsigned not null, c char(10), d int, primary key (a));
16
16
insert into t2 values (1,1,"a",1),(3,4,"A",4),(3,5,"B",5),(3,6,"C",6),(4,7,"D",7);
18
18
select t1.*,t2.* from t1 JOIN t2 where t1.a=t2.a;
28
28
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id=3;
29
29
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id is null;
32
31
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1;
34
32
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1;
36
34
select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
38
36
# The next query should rearange the left joins to get this to work
39
--error ER_BAD_FIELD_ERROR
40
38
explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
41
--error ER_BAD_FIELD_ERROR
42
40
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a);
44
42
# The next query should give an error in MySQL
45
--error ER_BAD_FIELD_ERROR
46
44
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a);
48
46
# Test of inner join
61
uniq_id INT NOT NULL AUTO_INCREMENT,
62
start_num INT NOT NULL DEFAULT 1,
63
increment INT NOT NULL DEFAULT 1,
58
usr_id INT unsigned NOT NULL,
59
uniq_id INT unsigned NOT NULL AUTO_INCREMENT,
60
start_num INT unsigned NOT NULL DEFAULT 1,
61
increment INT unsigned NOT NULL DEFAULT 1,
64
62
PRIMARY KEY (uniq_id),
65
63
INDEX usr_uniq_idx (usr_id, uniq_id),
66
64
INDEX uniq_usr_idx (uniq_id, usr_id)
69
id INT NOT NULL DEFAULT 0,
70
usr2_id INT NOT NULL DEFAULT 0,
71
max INT NOT NULL DEFAULT 0,
72
c_amount INT NOT NULL DEFAULT 0,
73
d_max INT NOT NULL DEFAULT 0,
74
d_num INT NOT NULL DEFAULT 0,
75
orig_time INT NOT NULL DEFAULT 0,
76
c_time INT NOT NULL DEFAULT 0,
67
id INT unsigned NOT NULL DEFAULT 0,
68
usr2_id INT unsigned NOT NULL DEFAULT 0,
69
max INT unsigned NOT NULL DEFAULT 0,
70
c_amount INT unsigned NOT NULL DEFAULT 0,
71
d_max INT unsigned NOT NULL DEFAULT 0,
72
d_num INT unsigned NOT NULL DEFAULT 0,
73
orig_time INT unsigned NOT NULL DEFAULT 0,
74
c_time INT unsigned NOT NULL DEFAULT 0,
77
75
active ENUM ("no","yes") NOT NULL,
78
76
PRIMARY KEY (id,usr2_id),
226
224
INSERT INTO t1 VALUES (3,'Thimble Smith');
228
226
CREATE TABLE t2 (
229
id int NOT NULL auto_increment,
230
owner int DEFAULT '0' NOT NULL,
227
id int unsigned NOT NULL auto_increment,
228
owner int unsigned DEFAULT '0' NOT NULL,
294
292
insert into t4 values (1,1);
295
293
insert into t5 values (1,1);
297
--error ER_BAD_FIELD_ERROR
298
296
explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23;
300
298
drop table t1,t2,t3,t4,t5;
420
415
# Test problem with LEFT JOIN
422
create table t1 (fooID int auto_increment, primary key (fooID));
423
create table t2 (fooID int not null, barID int not null, primary key (fooID,barID));
417
create table t1 (fooID int unsigned auto_increment, primary key (fooID));
418
create table t2 (fooID int unsigned not null, barID int unsigned not null, primary key (fooID,barID));
424
419
insert into t1 (fooID) values (10),(20),(30);
425
420
insert into t2 values (10,1),(20,2),(30,3);
426
421
explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30;
481
476
# Test for BUG#5088
483
478
create table t1 (
484
match_id int not null auto_increment,
485
home int default '0',
479
match_id int unsigned not null auto_increment,
480
home int unsigned default '0',
486
481
unique key match_id (match_id),
487
482
key match_id_2 (match_id)
490
485
insert into t1 values("1", "2");
492
487
create table t2 (
493
player_id int default '0',
494
match_1_h int default '0',
488
player_id int unsigned default '0',
489
match_1_h int unsigned default '0',
495
490
key player_id (player_id)
550
545
UNIQUE KEY ts_id (ts_id,inst_id,flag_name)
553
CREATE TEMPORARY TABLE t2 (
554
549
ts_id bigint default NULL,
555
550
inst_id int default NULL,
556
551
flag_name varchar(64) default NULL,
675
670
# BUG#10162 - ON is merged with WHERE, left join is convered to a regular join
677
create table t1 (gid int not null, x int not null, y int not null, art int not null, primary key (gid,x,y));
672
create table t1 (gid int unsigned not null, x int not null, y int not null, art int not null, primary key (gid,x,y));
678
673
insert t1 values (1, -5, -8, 2), (1, 2, 2, 1), (1, 1, 1, 1);
679
create table t2 (gid int not null, x int not null, y int not null, id int not null, primary key (gid,id,x,y), key id (id));
674
create table t2 (gid int unsigned not null, x int not null, y int not null, id int not null, primary key (gid,id,x,y), key id (id));
680
675
insert t2 values (1, -5, -8, 1), (1, 1, 1, 1), (1, 2, 2, 1);
681
create table t3 ( set_id int not null, id int not null, name char(12) not null, primary key (id,set_id));
676
create table t3 ( set_id int unsigned not null, id int unsigned not null, name char(12) not null, primary key (id,set_id));
682
677
insert t3 values (0, 1, 'a'), (1, 1, 'b'), (0, 2, 'c'), (1, 2, 'd'), (1, 3, 'e'), (1, 4, 'f'), (1, 5, 'g'), (1, 6, 'h');
683
678
explain select name from t1 left join t2 on t1.x = t2.x and t1.y = t2.y
684
679
left join t3 on t1.art = t3.id where t2.id =1 and t2.x = -5 and t2.y =-8