explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
id select_type table type possible_keys key key_len ref rows Extra
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
...
@@ -1388,14 +1412,26 @@ explain select t2.companynr,companyname from t4 left join t2 using (companynr) w
...
@@ -1388,14 +1412,26 @@ explain select t2.companynr,companyname from t4 left join t2 using (companynr) w
id select_type table type possible_keys key key_len ref rows Extra
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t4 ALL NULL NULL NULL NULL 12
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr companynr
companynr companynr
37 36
37 36
41 40
41 40
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
id select_type table type possible_keys key key_len ref rows Extra
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using temporary
1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 Using index; Using temporary
1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 Using where; Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008;
select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008;
id select_type table type possible_keys key key_len ref rows Extra
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where
Warnings:
Warnings:
Note 1003 select count(0) AS `count(*)`,min(test.t2.fld4) AS `min(fld4)`,max(test.t2.fld4) AS `max(fld4)`,sum(test.t2.fld1) AS `sum(fld1)`,avg(test.t2.fld1) AS `avg(fld1)`,std(test.t2.fld1) AS `std(fld1)`,variance(test.t2.fld1) AS `variance(fld1)` from test.t2 where ((test.t2.companynr = 34) and (test.t2.fld4 <> _latin1''))
Note 1003 select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld4` <> _latin1''))
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
00 82 Anthony windmills 10355753 126289.6707 115550.9757 13352027981.7087
00 82 Anthony windmills 10355753 126289.6707 115550.9757 13352027981.7087
...
@@ -1671,7 +1707,7 @@ fld1 count(*)
...
@@ -1671,7 +1707,7 @@ fld1 count(*)
158402 4181
158402 4181
select sum(Period)/count(*) from t1;
select sum(Period)/count(*) from t1;
sum(Period)/count(*)
sum(Period)/count(*)
9410.00
9410.0000
select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr;
select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr;
companynr count sum diff func
companynr count sum diff func
37 12543 309394878010 0.0000 464091
37 12543 309394878010 0.0000 464091
...
@@ -1683,7 +1719,7 @@ companynr count sum diff func
...
@@ -1683,7 +1719,7 @@ companynr count sum diff func
512 4181 3288532102 0.0000 2140672
512 4181 3288532102 0.0000 2140672
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
companynr avg
companynr avg
154 983543950.00
154 983543950.0000
select companynr,count(*) from t2 group by companynr order by 2 desc;
select companynr,count(*) from t2 group by companynr order by 2 desc;
companynr count(*)
companynr count(*)
37 588
37 588
...
@@ -2033,20 +2069,20 @@ show tables from test like "t?";
...
@@ -2033,20 +2069,20 @@ show tables from test like "t?";
Tables_in_test (t?)
Tables_in_test (t?)
show full columns from t2;
show full columns from t2;
Field Type Collation Null Key Default Extra Privileges Comment
Field Type Collation Null Key Default Extra Privileges Comment
auto int(11) NULL PRI NULL auto_increment #
auto int(11) NULL NO PRI NULL auto_increment #
fld1 int(6) unsigned zerofill NULL UNI 000000 #
fld1 int(6) unsigned zerofill NULL NO UNI 000000 #
companynr tinyint(2) unsigned zerofill NULL 00 #
companynr tinyint(2) unsigned zerofill NULL NO 00 #
fld3 char(30) latin1_swedish_ci MUL #
fld3 char(30) latin1_swedish_ci NO MUL #
fld4 char(35) latin1_swedish_ci #
fld4 char(35) latin1_swedish_ci NO #
fld5 char(35) latin1_swedish_ci #
fld5 char(35) latin1_swedish_ci NO #
fld6 char(4) latin1_swedish_ci #
fld6 char(4) latin1_swedish_ci NO #
show full columns from t2 from test like 'f%';
show full columns from t2 from test like 'f%';
Field Type Collation Null Key Default Extra Privileges Comment
Field Type Collation Null Key Default Extra Privileges Comment
fld1 int(6) unsigned zerofill NULL UNI 000000 #
fld1 int(6) unsigned zerofill NULL NO UNI 000000 #
fld3 char(30) latin1_swedish_ci MUL #
fld3 char(30) latin1_swedish_ci NO MUL #
fld4 char(35) latin1_swedish_ci #
fld4 char(35) latin1_swedish_ci NO #
fld5 char(35) latin1_swedish_ci #
fld5 char(35) latin1_swedish_ci NO #
fld6 char(4) latin1_swedish_ci #
fld6 char(4) latin1_swedish_ci NO #
show full columns from t2 from test like 's%';
show full columns from t2 from test like 's%';
Field Type Collation Null Key Default Extra Privileges Comment
Field Type Collation Null Key Default Extra Privileges Comment
show keys from t2;
show keys from t2;
...
@@ -2072,17 +2108,15 @@ INSERT INTO t1 (pseudo) VALUES ('test1');
...
@@ -2072,17 +2108,15 @@ INSERT INTO t1 (pseudo) VALUES ('test1');
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= 'wrong-date-value' AND b.sampletime < 'wrong-date-value' AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
SELECT a.gvid, (SUM(CASE b.sampletid WHEN 140 THEN b.samplevalue ELSE 0 END)) as the_success,(SUM(CASE b.sampletid WHEN 141 THEN b.samplevalue ELSE 0 END)) as the_fail,(SUM(CASE b.sampletid WHEN 142 THEN b.samplevalue ELSE 0 END)) as the_size,(SUM(CASE b.sampletid WHEN 143 THEN b.samplevalue ELSE 0 END)) as the_time FROM t1 a, t2 b WHERE a.hmid = b.hmid AND a.volid = b.volid AND b.sampletime >= NULL AND b.sampletime < NULL AND b.sampletid IN (140, 141, 142, 143) GROUP BY a.gvid;
gvid the_success the_fail the_size the_time
gvid the_success the_fail the_size the_time
DROP TABLE t1,t2;
DROP TABLE t1,t2;
...
@@ -2110,196 +2144,165 @@ select @b;
...
@@ -2110,196 +2144,165 @@ select @b;
aaaa
aaaa
select @c;
select @c;
@c
@c
6.26
6.260
create table t1 (a int not null auto_increment primary key);
create table t1 (a int not null auto_increment primary key);
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
a a a
a a
1 1 1
1 1
2 2 1
2 1
3 3 1
3 1
1 1 2
1 2
2 2 2
2 2
3 3 2
3 2
1 1 3
1 3
2 2 3
2 3
3 3 3
3 3
select * from t1, (t1 as t2 left join t1 as t3 using (a));
select * from t1, (t1 as t2 left join t1 as t3 using (a));
a a a
a a
1 1 1
1 1
2 1 1
2 1
3 1 1
3 1
1 2 2
1 2
2 2 2
2 2
3 2 2
3 2
1 3 3
1 3
2 3 3
2 3
3 3 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
a a a
a a
1 1 1
1 1
2 2 1
2 1
3 3 1
3 1
1 1 2
1 2
2 2 2
2 2
3 3 2
3 2
1 1 3
1 3
2 2 3
2 3
3 3 3
3 3
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
a a a
a a
1 1 1
1 1
2 1 1
2 1
3 1 1
3 1
1 2 2
1 2
2 2 2
2 2
3 2 2
3 2
1 3 3
1 3
2 3 3
2 3
3 3 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
a a a
a a
1 1 2
1 2
1 1 3
2 2
2 2 2
3 2
2 2 3
1 3
3 3 2
2 3
3 3 3
3 3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
a a
1 1 NULL
2 1
2 1 1
3 1
3 1 1
2 2
1 2 NULL
3 2
2 2 2
2 3
3 2 2
3 3
1 3 NULL
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
a
1 1 1
1
2 1 NULL
2
3 1 NULL
3
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a a a
a a
1 1 2
1 2
1 1 3
1 3
2 2 2
2 2
2 2 3
2 3
3 3 2
3 2
3 3 3
3 3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
a a
1 1 NULL
1 NULL
2 1 1
2 1
3 1 1
2 2
1 2 NULL
2 3
2 2 2
3 1
3 2 2
3 2
1 3 NULL
3 3
2 3 3
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
a
1 1 1
1
2 1 NULL
2
3 1 NULL
3
1 2 NULL
2 2 2
3 2 NULL
1 3 NULL
2 3 NULL
3 3 3
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
a a a
a a
1 NULL 1
NULL 1
2 NULL 1
1 2
3 NULL 1
2 2
1 1 2
3 2
2 2 2
1 3
3 3 2
2 3
1 1 3
3 3
2 2 3
3 3 3
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a a a
a a
2 1 1
2 1
3 1 1
3 1
2 2 2
2 2
3 2 2
3 2
2 3 3
2 3
3 3 3
3 3
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
a a a
a
1 1 1
1
2 NULL 1
2
3 NULL 1
3
1 NULL 2
2 2 2
3 NULL 2
1 NULL 3
2 NULL 3
3 3 3
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
a a a
a
1 1 1
1
2 NULL 1
2
3 NULL 1
3
1 NULL 2
2 2 2
3 NULL 2
1 NULL 3
2 NULL 3
3 3 3
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
a a
a
1 1
1
2 2
2
3 3
3
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
a a a
a
1 1 1
1
2 2 2
2
3 3 3
3
drop table t1;
drop table t1;
CREATE TABLE t1 ( aa char(2), id int(11) NOT NULL auto_increment, t2_id int(11) NOT NULL default '0', PRIMARY KEY (id), KEY replace_id (t2_id)) ENGINE=MyISAM;
CREATE TABLE t1 ( aa char(2), id int(11) NOT NULL auto_increment, t2_id int(11) NOT NULL default '0', PRIMARY KEY (id), KEY replace_id (t2_id)) ENGINE=MyISAM;
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);
...
@@ -2345,7 +2348,7 @@ select * from t2 where s = 'one';
...
@@ -2345,7 +2348,7 @@ select * from t2 where s = 'one';
s
s
select * from t3 where s = 'one';
select * from t3 where s = 'one';
s
s
one
one
select * from t1,t2 where t1.s = t2.s;
select * from t1,t2 where t1.s = t2.s;
s s
s s
two two
two two
...
@@ -2648,8 +2651,8 @@ create table t11 like t1;
...
@@ -2648,8 +2651,8 @@ create table t11 like t1;
insert into t1 values(1,""),(2,"");
insert into t1 values(1,""),(2,"");
show table status like 't1%';
show table status like 't1%';
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
t1 MyISAM 9 Dynamic 2 20 X X X X X X X X latin1_swedish_ci NULL
t1 MyISAM 10 Dynamic 2 20 X X X X X X X X latin1_swedish_ci NULL
t11 MyISAM 9 Dynamic 0 0 X X X X X X X X latin1_swedish_ci NULL
t11 MyISAM 10 Dynamic 0 0 X X X X X X X X latin1_swedish_ci NULL
select 123 as a from t1 where f1 is null;
select 123 as a from t1 where f1 is null;
a
a
drop table t1,t11;
drop table t1,t11;
...
@@ -2665,10 +2668,9 @@ a c
...
@@ -2665,10 +2668,9 @@ a c
drop table t1;
drop table t1;
CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) );
CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) );
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4);
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4);
CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, c INT );
CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, e INT );
select t1.x, t3.x from t1, t2, t3 where t1.x = t2.x and t3.x >= t1.y and t3.x <= t2.y;
x x
1 1
2 1
3 1
3 2
3 3
4 3
4 4
4 5
drop table t1,t2,t3;
create table t1 (id char(16) not null default '', primary key (id));
insert into t1 values ('100'),('101'),('102');
create table t2 (id char(16) default null);
insert into t2 values (1);
create view v1 as select t1.id from t1;
create view v2 as select t2.id from t2;
create view v3 as select (t1.id+2) as id from t1 natural left join t2;
select t1.id from t1 left join v2 using (id);
id
100
101
102
select t1.id from v2 right join t1 using (id);
id
100
101
102
select t1.id from t1 left join v3 using (id);
id
100
101
102
select * from t1 left join v2 using (id);
id
100
101
102
select * from v2 right join t1 using (id);
id
100
101
102
select * from t1 left join v3 using (id);
id
100
101
102
select v1.id from v1 left join v2 using (id);
id
100
101
102
select v1.id from v2 right join v1 using (id);
id
100
101
102
select v1.id from v1 left join v3 using (id);
id
100
101
102
select * from v1 left join v2 using (id);
id
100
101
102
select * from v2 right join v1 using (id);
id
100
101
102
select * from v1 left join v3 using (id);
id
100
101
102
drop table t1, t2;
drop view v1, v2, v3;
create table t1 (id int(11) not null default '0');
insert into t1 values (123),(191),(192);
create table t2 (id char(16) character set utf8 not null);
insert into t2 values ('58013'),('58014'),('58015'),('58016');
create table t3 (a_id int(11) not null, b_id char(16) character set utf8);
insert into t3 values (123,null),(123,null),(123,null),(123,null),(123,null),(123,'58013');
select count(*)
from t1 inner join (t3 left join t2 on t2.id = t3.b_id) on t1.id = t3.a_id;
count(*)
6
select count(*)
from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id;
count(*)
6
drop table t1,t2,t3;
create table t1 (a int);
create table t2 (b int);
create table t3 (c int);
select * from t1 join t2 join t3 on (t1.a=t3.c);
a b c
select * from t1 join t2 left join t3 on (t1.a=t3.c);
a b c
select * from t1 join t2 right join t3 on (t1.a=t3.c);
a b c
select * from t1 join t2 straight_join t3 on (t1.a=t3.c);
a b c
drop table t1, t2 ,t3;
create table t1(f1 int, f2 date);
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
(4,'2005-10-01'),(5,'2005-12-30');
select * from t1 where f2 >= 0;
f1 f2
1 2005-01-01
2 2005-09-01
3 2005-09-30
4 2005-10-01
5 2005-12-30
select * from t1 where f2 >= '0000-00-00';
f1 f2
1 2005-01-01
2 2005-09-01
3 2005-09-30
4 2005-10-01
5 2005-12-30
select * from t1 where f2 >= '2005-09-31';
f1 f2
4 2005-10-01
5 2005-12-30
select * from t1 where f2 >= '2005-09-3a';
f1 f2
4 2005-10-01
5 2005-12-30
Warnings:
Warning 1292 Incorrect date value: '2005-09-3a' for column 'f2' at row 1
select * from t1 where f2 <= '2005-09-31';
f1 f2
1 2005-01-01
2 2005-09-01
3 2005-09-30
select * from t1 where f2 <= '2005-09-3a';
f1 f2
1 2005-01-01
2 2005-09-01
3 2005-09-30
Warnings:
Warning 1292 Incorrect date value: '2005-09-3a' for column 'f2' at row 1
drop table t1;
create table t1 (f1 int, f2 int);
insert into t1 values (1, 30), (2, 20), (3, 10);
create algorithm=merge view v1 as select f1, f2 from t1;
create algorithm=merge view v2 (f2, f1) as select f1, f2 from t1;
create algorithm=merge view v3 as select t1.f1 as f2, t1.f2 as f1 from t1;
select t1.f1 as x1, f1 from t1 order by t1.f1;
x1 f1
1 1
2 2
3 3
select v1.f1 as x1, f1 from v1 order by v1.f1;
x1 f1
1 1
2 2
3 3
select v2.f1 as x1, f1 from v2 order by v2.f1;
x1 f1
10 10
20 20
30 30
select v3.f1 as x1, f1 from v3 order by v3.f1;
x1 f1
10 10
20 20
30 30
select f1, f2, v1.f1 as x1 from v1 order by v1.f1;
f1 f2 x1
1 30 1
2 20 2
3 10 3
select f1, f2, v2.f1 as x1 from v2 order by v2.f1;
f1 f2 x1
10 3 10
20 2 20
30 1 30
select f1, f2, v3.f1 as x1 from v3 order by v3.f1;
f1 f2 x1
10 3 10
20 2 20
30 1 30
drop table t1;
drop view v1, v2, v3;
CREATE TABLE t1(key_a int4 NOT NULL, optimus varchar(32), PRIMARY KEY(key_a));
CREATE TABLE t2(key_a int4 NOT NULL, prime varchar(32), PRIMARY KEY(key_a));
CREATE table t3(key_a int4 NOT NULL, key_b int4 NOT NULL, foo varchar(32),
PRIMARY KEY(key_a,key_b));
INSERT INTO t1 VALUES (0,'');
INSERT INTO t1 VALUES (1,'i');
INSERT INTO t1 VALUES (2,'j');
INSERT INTO t1 VALUES (3,'k');
INSERT INTO t2 VALUES (1,'r');
INSERT INTO t2 VALUES (2,'s');
INSERT INTO t2 VALUES (3,'t');
INSERT INTO t3 VALUES (1,5,'x');
INSERT INTO t3 VALUES (1,6,'y');
INSERT INTO t3 VALUES (2,5,'xx');
INSERT INTO t3 VALUES (2,6,'yy');
INSERT INTO t3 VALUES (2,7,'zz');
INSERT INTO t3 VALUES (3,5,'xxx');
SELECT t2.key_a,foo
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
key_a foo
2 xx
EXPLAIN SELECT t2.key_a,foo
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 Using index
1 SIMPLE t3 const PRIMARY PRIMARY 8 const,const 1
SELECT t2.key_a,foo
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
key_a foo
2 xx
EXPLAIN SELECT t2.key_a,foo
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
INNER JOIN t3 ON t1.key_a = t3.key_a
WHERE t2.key_a=2 and key_b=5;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 Using index
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 Using index
1 SIMPLE t3 const PRIMARY PRIMARY 8 const,const 1
DROP TABLE t1,t2,t3;
create table t1 (f1 int);
insert into t1 values(1),(2);
create table t2 (f2 int, f3 int, key(f2));
insert into t2 values(1,1),(2,2);
create table t3 (f4 int not null);
insert into t3 values (2),(2),(2);
select f1,(select count(*) from t2,t3 where f2=f1 and f3=f4) as count from t1;
f1 count
1 0
2 3
drop table t1,t2,t3;
create table t1 (f1 int unique);
create table t2 (f2 int unique);
create table t3 (f3 int unique);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
insert into t3 values(1),(NULL);
select * from t3 where f3 is null;
f3
NULL
select t2.f2 from t1 left join t2 on f1=f2 join t3 on f1=f3 where f1=1;
f2
1
drop table t1,t2,t3;
create table t1(f1 char, f2 char not null);
insert into t1 values(null,'a');
create table t2 (f2 char not null);
insert into t2 values('b');
select * from t1 left join t2 on f1=t2.f2 where t1.f2='a';
f1 f2 f2
NULL a NULL
drop table t1,t2;
select * from (select * left join t on f1=f2) tt;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'on f1=f2) tt' at line 1
CREATE TABLE t1 (sku int PRIMARY KEY, pr int);
CREATE TABLE t2 (sku int PRIMARY KEY, sppr int, name varchar(255));