377
377
ERROR 21000: Subquery returns more than 1 row
378
378
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
379
379
CREATE TABLE `t1` (
380
`topic` bigint(8) unsigned NOT NULL default '0',
380
`topic` bigint unsigned NOT NULL default '0',
381
381
`date` date NOT NULL default '0000-00-00',
382
382
`pseudo` varchar(35) character set latin1 NOT NULL default '',
383
383
PRIMARY KEY (`pseudo`,`date`,`topic`),
419
419
Note 1003 select 1 AS "1" from "test"."t1" where 1
421
421
CREATE TABLE `t1` (
422
`numeropost` bigint(8) unsigned NOT NULL auto_increment,
423
`maxnumrep` int(10) unsigned NOT NULL default '0',
422
`numeropost` bigint unsigned NOT NULL auto_increment,
423
`maxnumrep` int unsigned NOT NULL default '0',
424
424
PRIMARY KEY (`numeropost`),
425
425
UNIQUE KEY `maxnumrep` (`maxnumrep`)
426
426
) ENGINE=MyISAM ROW_FORMAT=FIXED;
427
427
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
428
428
CREATE TABLE `t2` (
429
429
`mot` varchar(30) NOT NULL default '',
430
`topic` bigint(8) unsigned NOT NULL default '0',
430
`topic` bigint unsigned NOT NULL default '0',
431
431
`date` date NOT NULL default '0000-00-00',
432
432
`pseudo` varchar(35) NOT NULL default '',
433
433
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`)
1030
1030
SHOW CREATE TABLE t1;
1031
1031
Table Create Table
1032
1032
t1 CREATE TABLE "t1" (
1033
"a" int(1) NOT NULL,
1034
"(SELECT 1)" int(1) NOT NULL
1034
"(SELECT 1)" int NOT NULL
1035
1035
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1037
1037
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
1038
1038
SHOW CREATE TABLE t1;
1039
1039
Table Create Table
1040
1040
t1 CREATE TABLE "t1" (
1041
"a" int(1) NOT NULL,
1042
"(SELECT a)" int(1) NOT NULL
1042
"(SELECT a)" int NOT NULL
1043
1043
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1045
1045
CREATE TABLE t1 SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
1046
1046
SHOW CREATE TABLE t1;
1047
1047
Table Create Table
1048
1048
t1 CREATE TABLE "t1" (
1049
"a" int(1) NOT NULL,
1050
"(SELECT a+0)" int(3) NOT NULL
1050
"(SELECT a+0)" int NOT NULL
1051
1051
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1053
1053
CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
1074
1074
select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent);
1075
1075
ERROR 42S02: Table 'test.t1' doesn't exist
1076
1076
CREATE TABLE t1 (
1077
ID int(11) NOT NULL auto_increment,
1077
ID int NOT NULL auto_increment,
1078
1078
name char(35) NOT NULL default '',
1079
1079
t2 char(3) NOT NULL default '',
1080
1080
District char(20) NOT NULL default '',
1081
Population int(11) NOT NULL default '0',
1081
Population int NOT NULL default '0',
1082
1082
PRIMARY KEY (ID)
1083
1083
) ENGINE=MyISAM;
1084
1084
INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
1090
1090
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1091
1091
Region char(26) NOT NULL default '',
1092
1092
SurfaceArea float(10,2) NOT NULL default '0.00',
1093
IndepYear smallint(6) default NULL,
1094
Population int(11) NOT NULL default '0',
1093
IndepYear smallint default NULL,
1094
Population int NOT NULL default '0',
1095
1095
LifeExpectancy float(3,1) default NULL,
1096
1096
GNP float(10,2) default NULL,
1097
1097
GNPOld float(10,2) default NULL,
1098
1098
LocalName char(45) NOT NULL default '',
1099
1099
GovernmentForm char(45) NOT NULL default '',
1100
1100
HeadOfState char(60) default NULL,
1101
Capital int(11) default NULL,
1101
Capital int default NULL,
1102
1102
Code2 char(2) NOT NULL default '',
1103
1103
PRIMARY KEY (Code)
1104
1104
) ENGINE=MyISAM;
1181
1181
Note 1003 select "test"."t1"."id" AS "id" from "test"."t1" where ("test"."t1"."salary" = (select max("test"."t1"."salary") AS "MAX(salary)" from "test"."t1"))
1183
1183
CREATE TABLE t1 (
1184
ID int(10) unsigned NOT NULL auto_increment,
1185
SUB_ID int(3) unsigned NOT NULL default '0',
1186
REF_ID int(10) unsigned default NULL,
1187
REF_SUB int(3) unsigned default '0',
1184
ID int unsigned NOT NULL auto_increment,
1185
SUB_ID int unsigned NOT NULL default '0',
1186
REF_ID int unsigned default NULL,
1187
REF_SUB int unsigned default '0',
1188
1188
PRIMARY KEY (ID,SUB_ID),
1189
1189
UNIQUE KEY t1_PK (ID,SUB_ID),
1190
1190
KEY t1_FK (REF_ID,REF_SUB),
1405
1405
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1406
1406
id select_type table type possible_keys key key_len ref rows filtered Extra
1407
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1408
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1407
1 PRIMARY t1 index NULL s1 8 NULL 3 100.00 Using index
1408
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 8 func 2 100.00 Using index; Full scan on NULL key
1410
1410
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 NOT IN (SELECT s1 FROM t2)" from "test"."t1"
1411
1411
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
1412
1412
id select_type table type possible_keys key key_len ref rows filtered Extra
1413
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1414
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1413
1 PRIMARY t1 index NULL s1 8 NULL 3 100.00 Using index
1414
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 8 func 2 100.00 Using index; Full scan on NULL key
1416
1416
Note 1003 select "test"."t1"."s1" AS "s1",<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))) AS "s1 = ANY (SELECT s1 FROM t2)" from "test"."t1"
1417
1417
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
1418
1418
id select_type table type possible_keys key key_len ref rows filtered Extra
1419
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1420
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1419
1 PRIMARY t1 index NULL s1 8 NULL 3 100.00 Using index
1420
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 8 func 2 100.00 Using index; Full scan on NULL key
1422
1422
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 <> ALL (SELECT s1 FROM t2)" from "test"."t1"
1423
1423
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
1424
1424
id select_type table type possible_keys key key_len ref rows filtered Extra
1425
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1426
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
1425
1 PRIMARY t1 index NULL s1 8 NULL 3 100.00 Using index
1426
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 8 func 2 100.00 Using index; Using where; Full scan on NULL key
1428
1428
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL where ("test"."t2"."s1" < 'a2') having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')" from "test"."t1"
1429
1429
drop table t1,t2;
1513
1513
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where <not>(("test"."t3"."a" <= <max>(select max("test"."t2"."b") AS "max(b)" from "test"."t2" group by "test"."t2"."a")))
1514
1514
drop table t2, t3;
1515
CREATE TABLE `t1` ( `id` bigint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
1515
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
1516
1516
INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
1517
CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
1517
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint NOT NULL default '0',`secondary_uid` smallint NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
1518
1518
INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
1519
CREATE TABLE `t3` (`taskgenid` bigint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
1519
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` tinyint NOT NULL default '1',`tues` tinyint NOT NULL default '1',`wed` tinyint NOT NULL default '1',`thur` tinyint NOT NULL default '1',`fri` tinyint NOT NULL default '1',`sat` tinyint NOT NULL default '0',`sun` tinyint NOT NULL default '0',`how_often` smallint NOT NULL default '1',`userid` smallint NOT NULL default '0',`active` tinyint NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
1520
1520
INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
1521
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
1521
CREATE TABLE `t4` (`task_id` smallint NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
1522
1522
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
1523
1523
select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
1524
1524
dbid name (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')
1594
1594
CREATE TABLE `t1` (
1595
`id` int(11) NOT NULL auto_increment,
1596
`id_cns` tinyint(3) unsigned NOT NULL default '0',
1595
`id` int NOT NULL auto_increment,
1596
`id_cns` tinyint unsigned NOT NULL default '0',
1597
1597
`tipo` enum('','UNO','DUE') NOT NULL default '',
1598
`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
1599
`particolare` bigint(8) unsigned NOT NULL default '0',
1600
`generale` bigint(8) unsigned NOT NULL default '0',
1601
`bis` tinyint(3) unsigned NOT NULL default '0',
1598
`anno_dep` smallint unsigned NOT NULL default '0',
1599
`particolare` bigint unsigned NOT NULL default '0',
1600
`generale` bigint unsigned NOT NULL default '0',
1601
`bis` tinyint unsigned NOT NULL default '0',
1602
1602
PRIMARY KEY (`id`),
1603
1603
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
1604
1604
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
1606
1606
INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
1607
1607
CREATE TABLE `t2` (
1608
`id` tinyint(3) unsigned NOT NULL auto_increment,
1609
`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
1608
`id` tinyint unsigned NOT NULL auto_increment,
1609
`max_anno_dep` smallint unsigned NOT NULL default '0',
1610
1610
PRIMARY KEY (`id`)
1612
1612
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
2218
2218
DROP TABLE t1, t2;
2219
CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
2219
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL);
2220
2220
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
2221
CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
2221
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL);
2222
2222
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
2223
2223
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
2247
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
2248
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
2247
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
2248
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY (`aid`,`bid`));
2249
2249
insert into t1 values (1,1),(1,2),(2,1),(2,2);
2250
2250
insert into t2 values (1,2),(2,2);
2251
2251
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2303
2303
select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x;
2304
2304
(select b.x from t1 as b where b.x=a.x)
2306
CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
2306
CREATE TABLE `t1` ( `master` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `slave` int unsigned NOT NULL default '0', `access` int unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
2307
2307
INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
2308
CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
2308
CREATE TABLE `t2` ( `id` int unsigned NOT NULL default '0', `pid` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `level` tinyint unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
2309
2309
INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
2310
2310
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
2311
2311
ERROR 42S22: Unknown column 'b.sc' in 'field list'
2347
2347
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
2348
2348
Region char(26) NOT NULL default '',
2349
2349
SurfaceArea float(10,2) NOT NULL default '0.00',
2350
IndepYear smallint(6) default NULL,
2351
Population int(11) NOT NULL default '0',
2350
IndepYear smallint default NULL,
2351
Population int NOT NULL default '0',
2352
2352
LifeExpectancy float(3,1) default NULL,
2353
2353
GNP float(10,2) default NULL,
2354
2354
GNPOld float(10,2) default NULL,
2355
2355
LocalName char(45) NOT NULL default '',
2356
2356
GovernmentForm char(45) NOT NULL default '',
2357
2357
HeadOfState char(60) default NULL,
2358
Capital int(11) default NULL,
2358
Capital int default NULL,
2359
2359
Code2 char(2) NOT NULL default ''
2360
2360
) ENGINE=MyISAM;
2361
2361
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
2440
2440
(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
2441
2441
(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
2442
2442
CREATE TABLE t3 (
2443
groupId int(11) NOT NULL,
2444
parentId int(11) NOT NULL,
2443
groupId int NOT NULL,
2444
parentId int NOT NULL,
2445
2445
startDate datetime NOT NULL,
2446
2446
endDate datetime NOT NULL,
2447
2447
createDate datetime NOT NULL,
2448
2448
modifyDate timestamp NOT NULL,
2451
2451
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
2452
2452
CREATE TABLE t4 (
2453
id int(11) NOT NULL,
2454
groupTypeId int(11) NOT NULL,
2454
groupTypeId int NOT NULL,
2455
2455
groupKey varchar(50) NOT NULL,
2458
2458
description text,
2459
2459
createDate datetime NOT NULL,
2460
2460
modifyDate timestamp NOT NULL
2534
2534
ERROR 21000: Operand should contain 2 column(s)
2536
2536
CREATE TABLE `t1` (
2537
`itemid` bigint(20) unsigned NOT NULL auto_increment,
2538
`sessionid` bigint(20) unsigned default NULL,
2539
`time` int(10) unsigned NOT NULL default '0',
2537
`itemid` bigint unsigned NOT NULL auto_increment,
2538
`sessionid` bigint unsigned default NULL,
2539
`time` int unsigned NOT NULL default '0',
2540
2540
`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
2541
2541
NULL default '',
2542
2542
`data` text collate latin1_general_ci NOT NULL,
2544
2544
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
2545
2545
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
2546
2546
CREATE TABLE `t2` (
2547
`sessionid` bigint(20) unsigned NOT NULL auto_increment,
2548
`pid` int(10) unsigned NOT NULL default '0',
2549
`date` int(10) unsigned NOT NULL default '0',
2547
`sessionid` bigint unsigned NOT NULL auto_increment,
2548
`pid` int unsigned NOT NULL default '0',
2549
`date` int unsigned NOT NULL default '0',
2550
2550
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
2551
2551
PRIMARY KEY (`sessionid`)
2552
2552
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
2976
2976
DROP TABLE t1,t2,t3;
2977
2977
CREATE TABLE `t1` (
2978
`itemid` bigint(20) unsigned NOT NULL auto_increment,
2979
`sessionid` bigint(20) unsigned default NULL,
2980
`time` int(10) unsigned NOT NULL default '0',
2978
`itemid` bigint unsigned NOT NULL auto_increment,
2979
`sessionid` bigint unsigned default NULL,
2980
`time` int unsigned NOT NULL default '0',
2981
2981
`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
2982
2982
NULL default '',
2983
2983
`data` text collate latin1_general_ci NOT NULL,
2985
2985
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
2986
2986
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
2987
2987
CREATE TABLE `t2` (
2988
`sessionid` bigint(20) unsigned NOT NULL auto_increment,
2989
`pid` int(10) unsigned NOT NULL default '0',
2990
`date` int(10) unsigned NOT NULL default '0',
2988
`sessionid` bigint unsigned NOT NULL auto_increment,
2989
`pid` int unsigned NOT NULL default '0',
2990
`date` int unsigned NOT NULL default '0',
2991
2991
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
2992
2992
PRIMARY KEY (`sessionid`)
2993
2993
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
3248
3248
CREATE TABLE t1 (
3249
id bigint(20) unsigned NOT NULL auto_increment,
3249
id bigint unsigned NOT NULL auto_increment,
3250
3250
name varchar(255) NOT NULL,
3251
3251
PRIMARY KEY (id)
3253
3253
INSERT INTO t1 VALUES
3254
3254
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
3255
3255
CREATE TABLE t2 (
3256
id bigint(20) unsigned NOT NULL auto_increment,
3257
mid bigint(20) unsigned NOT NULL,
3256
id bigint unsigned NOT NULL auto_increment,
3257
mid bigint unsigned NOT NULL,
3258
3258
date date NOT NULL,
3259
3259
PRIMARY KEY (id)
3814
3814
DROP TABLE t1, t2;
3815
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
3816
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
3817
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
3819
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
3821
CREATE INDEX I1 ON t1 (s1);
3822
CREATE INDEX I2 ON t1 (s2);
3823
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
3825
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
3828
INSERT INTO t1 VALUES (0x41,0x41);
3829
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
3832
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
3833
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
3834
CREATE TABLE t3 (a3 BINARY(2) default '0');
3835
INSERT INTO t1 VALUES (1),(2),(3),(4);
3836
INSERT INTO t2 VALUES (1),(2),(3);
3837
INSERT INTO t3 VALUES (1),(2),(3);
3838
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
3843
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
3844
a1 t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
3849
DROP TABLE t1,t2,t3;
3850
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
3851
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
3852
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
3853
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
3854
INSERT INTO t2 VALUES (2), (3), (4), (5);
3855
INSERT INTO t3 VALUES (10), (20), (30);
3856
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
3861
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
3863
DROP TABLE t1, t2, t3;
3864
3815
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
3865
3816
INSERT INTO t1 VALUES ('a', 'aa');
3866
3817
INSERT INTO t1 VALUES ('a', 'aaa');