@@ -17,7 +17,22 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 1);
...
@@ -17,7 +17,22 @@ SELECT (SELECT 1),MAX(1) FROM (SELECT 1);
1 1
1 1
SELECT (SELECT a) as a;
SELECT (SELECT a) as a;
Reference 'a' not supported (forward reference in item list)
Reference 'a' not supported (forward reference in item list)
drop table if exists t1,t2,t3,t4,t5,attend,clinic,inscrit;
EXPLAIN SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system NULL NULL NULL NULL 1
3 DEPENDENT SUBSELECT No tables used
2 DERIVED No tables used
SELECT 1 FROM (SELECT 1 as a) HAVING (SELECT a)=1;
1
1
SELECT (SELECT 1), a;
Unknown column 'a' in 'field list'
SELECT 1 as a FROM (SELECT 1) HAVING (SELECT a)=1;
a
1
SELECT 1 FROM (SELECT (SELECT a));
Unknown column 'a' in 'field list'
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
create table t1 (a int);
create table t1 (a int);
create table t2 (a int, b int);
create table t2 (a int, b int);
create table t3 (a int);
create table t3 (a int);
...
@@ -140,11 +155,11 @@ id select_type table type possible_keys key key_len ref rows Extra
...
@@ -140,11 +155,11 @@ id select_type table type possible_keys key key_len ref rows Extra
3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 Using where
3 DEPENDENT UNION t5 ALL NULL NULL NULL NULL 2 Using where
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
Subselect returns more than 1 record
Subselect returns more than 1 record
create table attend (patient_uq int, clinic_uq int, index i1 (clinic_uq));
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
create table clinic( uq int primary key, name char(25));
create table t7( uq int primary key, name char(25));
insert into clinic values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
insert into attend values (1,1),(1,2),(2,2),(1,3);
insert into t6 values (1,1),(1,2),(2,2),(1,3);
select * from attend where exists (select * from clinic where uq = clinic_uq);
select * from t6 where exists (select * from t7 where uq = clinic_uq);
patient_uq clinic_uq
patient_uq clinic_uq
1 1
1 1
1 2
1 2
...
@@ -167,117 +182,113 @@ W 1
...
@@ -167,117 +182,113 @@ W 1
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
a b
a b
W a
W a
drop table if exists inscrit;
drop table if exists t8;
CREATE TABLE `inscrit` (
CREATE TABLE `t8` (
`pseudo` varchar(35) character set latin1 NOT NULL default '',
`pseudo` varchar(35) character set latin1 NOT NULL default '',
`email` varchar(60) character set latin1 NOT NULL default '',
`email` varchar(60) character set latin1 NOT NULL default '',
PRIMARY KEY (`pseudo`),
PRIMARY KEY (`pseudo`),
UNIQUE KEY `email` (`email`)
UNIQUE KEY `email` (`email`)
) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
) TYPE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
INSERT INTO inscrit (pseudo,email) VALUES ('joce','test');
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
INSERT INTO inscrit (pseudo,email) VALUES ('joce1','test1');
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
INSERT INTO inscrit (pseudo,email) VALUES ('2joce1','2test1');
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
EXPLAIN SELECT pseudo,(SELECT email FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce')) FROM inscrit WHERE pseudo=(SELECT pseudo FROM inscrit WHERE pseudo='joce');
EXPLAIN SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
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
EXPLAIN SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
EXPLAIN SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
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 searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 Using where; Using index
1 SIMPLE t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
EXPLAIN SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
EXPLAIN SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
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 PRIMARY No tables used
1 PRIMARY No tables used
2 SUBSELECT searchconthardwarefr3 index NULL PRIMARY 41 NULL 2 Using where; Using index
2 SUBSELECT t1 index NULL PRIMARY 41 NULL 2 Using where; Using index
SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03';
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
date
date
2002-08-03
2002-08-03
SELECT (SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03');
SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
(SELECT DISTINCT date FROM searchconthardwarefr3 WHERE date='2002-08-03')
(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')
2002-08-03
2002-08-03
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
1
1
1
1
1
1
1
1
SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
Subselect returns more than 1 record
Subselect returns more than 1 record
EXPLAIN SELECT 1 FROM searchconthardwarefr3 WHERE 1=(SELECT 1 UNION SELECT 1);
EXPLAIN SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 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 PRIMARY searchconthardwarefr3 index NULL topic 3 NULL 2 Using index
1 PRIMARY t1 index NULL topic 3 NULL 2 Using index
2 SUBSELECT No tables used
2 SUBSELECT No tables used
3 UNION No tables used
3 UNION No tables used
drop table searchconthardwarefr3;
drop table t1;
drop table if exists forumconthardwarefr7, searchconthardwarefr7;
CREATE TABLE `t1` (
CREATE TABLE `forumconthardwarefr7` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0',
`maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`),
PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`)
UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED;
) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
CREATE TABLE `searchconthardwarefr7` (
CREATE TABLE `t2` (
`mot` varchar(30) NOT NULL default '',
`mot` varchar(30) NOT NULL default '',
`topic` mediumint(8) unsigned NOT NULL default '0',
`topic` mediumint(8) unsigned NOT NULL default '0',
`date` date NOT NULL default '0000-00-00',
`date` date NOT NULL default '0000-00-00',
`pseudo` varchar(35) NOT NULL default '',
`pseudo` varchar(35) NOT NULL default '',
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
) TYPE=MyISAM ROW_FORMAT=DYNAMIC;
INSERT INTO searchconthardwarefr7 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1);
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
a
a
40143
40143
SELECT numeropost,maxnumrep FROM forumconthardwarefr7 WHERE exists (SELECT 1 FROM searchconthardwarefr7 WHERE (mot='joce') AND date >= '2002-10-21' AND forumconthardwarefr7.numeropost = searchconthardwarefr7.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
numeropost maxnumrep
numeropost maxnumrep
43506 2
43506 2
40143 1
40143 1
SELECT (SELECT 1) as a FROM (SELECT 1 FROM forumconthardwarefr7 HAVING a=1);
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1);
Unknown column 'a' in 'having clause'
Unknown column 'a' in 'having clause'
drop table forumconthardwarefr7, searchconthardwarefr7;
drop table t1, t2;
drop table if exists forumconthardwarefr7;
drop table if exists t1;
CREATE TABLE `forumconthardwarefr7` (
CREATE TABLE `t1` (
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
`maxnumrep` int(10) unsigned NOT NULL default '0',
`maxnumrep` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`numeropost`),
PRIMARY KEY (`numeropost`),
UNIQUE KEY `maxnumrep` (`maxnumrep`)
UNIQUE KEY `maxnumrep` (`maxnumrep`)
) TYPE=MyISAM ROW_FORMAT=FIXED;
) TYPE=MyISAM ROW_FORMAT=FIXED;
INSERT INTO forumconthardwarefr7 (numeropost,maxnumrep) VALUES (1,0),(2,1);
INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
select numeropost as a FROM forumconthardwarefr7 GROUP BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1);
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
Subselect returns more than 1 record
Subselect returns more than 1 record
select numeropost as a FROM forumconthardwarefr7 ORDER BY (SELECT 1 FROM forumconthardwarefr7 HAVING a=1);
select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
Subselect returns more than 1 record
Subselect returns more than 1 record
drop table if exists forumconthardwarefr7;
drop table t1;
drop table if exists iftest;
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b');
CREATE TABLE iftest (field char(1) NOT NULL DEFAULT 'b');
INSERT INTO t1 VALUES ();
INSERT INTO iftest VALUES ();
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b');
SELECT field FROM iftest WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) HAVING field='b');
Subselect returns more than 1 record
Subselect returns more than 1 record
drop table iftest;
drop table t1;
drop table if exists threadhardwarefr7;
CREATE TABLE `t1` (
CREATE TABLE `threadhardwarefr7` (
`numeropost` mediumint(8) unsigned NOT NULL default '0',
`numeropost` mediumint(8) unsigned NOT NULL default '0',
`numreponse` int(10) unsigned NOT NULL auto_increment,
`numreponse` int(10) unsigned NOT NULL auto_increment,
SELECT (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a),numreponse FROM (SELECT * FROM threadhardwarefr7) as a;
SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
Reference 'numreponse' not supported (forward reference in item list)
Reference 'numreponse' not supported (forward reference in item list)
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=a) FROM (SELECT * FROM threadhardwarefr7) as a;
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
Unknown column 'a' in 'having clause'
Unknown column 'a' in 'having clause'
SELECT numreponse, (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=1) FROM (SELECT * FROM threadhardwarefr7) as a;
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
numreponse (SELECT numeropost FROM threadhardwarefr7 HAVING numreponse=1)
numreponse (SELECT numeropost FROM t1 HAVING numreponse=1)
INSERT INTO threadhardwarefr7 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM threadhardwarefr7 WHERE numeropost='1');
EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
Subselect returns more than 1 record
Subselect returns more than 1 record
EXPLAIN SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1';
EXPLAIN SELECT MAX(numreponse) FROM t1 WHERE numeropost='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 Select tables optimized away
1 SIMPLE Select tables optimized away
EXPLAIN SELECT numreponse FROM threadhardwarefr7 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM threadhardwarefr7 WHERE numeropost='1');
EXPLAIN SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='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