drop table if exists t1,t2,t3; create table t1 (id int primary key); create table t2 (id int); insert into t1 values (75); insert into t1 values (79); insert into t1 values (78); insert into t1 values (77); replace into t1 values (76); replace into t1 values (76); insert into t1 values (104); insert into t1 values (103); insert into t1 values (102); insert into t1 values (101); insert into t1 values (105); insert into t1 values (106); insert into t1 values (107); insert into t2 values (107); insert into t2 values (75); select t1.id, t2.id from t1, t2 where t2.id = t1.id; id id 107 107 75 75 select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t1.id; id count(t2.id) 75 1 107 1 select t1.id, count(t2.id) from t1,t2 where t2.id = t1.id group by t2.id; id count(t2.id) 75 1 107 1 drop table t1,t2; CREATE TABLE t1 ( id int(11) NOT NULL auto_increment, token varchar(100) DEFAULT '' NOT NULL, count int(11) DEFAULT '0' NOT NULL, qty int(11), phone char(1) DEFAULT '' NOT NULL, timestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id), KEY token (token(15)), KEY timestamp (timestamp), UNIQUE token_2 (token(75),count,phone) ); INSERT INTO t1 VALUES (21,'e45703b64de71482360de8fec94c3ade',3,7800,'n','1999-12-23 17:22:21'); INSERT INTO t1 VALUES (22,'e45703b64de71482360de8fec94c3ade',4,5000,'y','1999-12-23 17:22:21'); INSERT INTO t1 VALUES (18,'346d1cb63c89285b2351f0ca4de40eda',3,13200,'b','1999-12-23 11:58:04'); INSERT INTO t1 VALUES (17,'ca6ddeb689e1b48a04146b1b5b6f936a',4,15000,'b','1999-12-23 11:36:53'); INSERT INTO t1 VALUES (16,'ca6ddeb689e1b48a04146b1b5b6f936a',3,13200,'b','1999-12-23 11:36:53'); INSERT INTO t1 VALUES (26,'a71250b7ed780f6ef3185bfffe027983',5,1500,'b','1999-12-27 09:44:24'); INSERT INTO t1 VALUES (24,'4d75906f3c37ecff478a1eb56637aa09',3,5400,'y','1999-12-23 17:29:12'); INSERT INTO t1 VALUES (25,'4d75906f3c37ecff478a1eb56637aa09',4,6500,'y','1999-12-23 17:29:12'); INSERT INTO t1 VALUES (27,'a71250b7ed780f6ef3185bfffe027983',3,6200,'b','1999-12-27 09:44:24'); INSERT INTO t1 VALUES (28,'a71250b7ed780f6ef3185bfffe027983',3,5400,'y','1999-12-27 09:44:36'); INSERT INTO t1 VALUES (29,'a71250b7ed780f6ef3185bfffe027983',4,17700,'b','1999-12-27 09:45:05'); CREATE TABLE t2 ( id int(11) NOT NULL auto_increment, category int(11) DEFAULT '0' NOT NULL, county int(11) DEFAULT '0' NOT NULL, state int(11) DEFAULT '0' NOT NULL, phones int(11) DEFAULT '0' NOT NULL, nophones int(11) DEFAULT '0' NOT NULL, PRIMARY KEY (id), KEY category (category,county,state) ); INSERT INTO t2 VALUES (3,2,11,12,5400,7800); INSERT INTO t2 VALUES (4,2,25,12,6500,11200); INSERT INTO t2 VALUES (5,1,37,6,10000,12000); select a.id, b.category as catid, b.state as stateid, b.county as countyid from t1 a, t2 b where (a.token = 'a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id); id catid stateid countyid 27 2 12 11 28 2 12 11 29 2 12 25 26 1 6 37 select a.id, b.category as catid, b.state as stateid, b.county as countyid from t1 a, t2 b where (a.token = 'a71250b7ed780f6ef3185bfffe027983') and (a.count = b.id) order by a.id; id catid stateid countyid 26 1 6 37 27 2 12 11 28 2 12 11 29 2 12 25 drop table t1, t2; create table t1 (a int primary key); insert into t1 values(1),(2); select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a); a 1 2 select t1.a from t1 as t1 left join t1 as t2 using (a) left join t1 as t3 using (a) left join t1 as t4 using (a) left join t1 as t5 using (a) left join t1 as t6 using (a) left join t1 as t7 using (a) left join t1 as t8 using (a) left join t1 as t9 using (a) left join t1 as t10 using (a) left join t1 as t11 using (a) left join t1 as t12 using (a) left join t1 as t13 using (a) left join t1 as t14 using (a) left join t1 as t15 using (a) left join t1 as t16 using (a) left join t1 as t17 using (a) left join t1 as t18 using (a) left join t1 as t19 using (a) left join t1 as t20 using (a) left join t1 as t21 using (a) left join t1 as t22 using (a) left join t1 as t23 using (a) left join t1 as t24 using (a) left join t1 as t25 using (a) left join t1 as t26 using (a) left join t1 as t27 using (a) left join t1 as t28 using (a) left join t1 as t29 using (a) left join t1 as t30 using (a) left join t1 as t31 using (a) left join t1 as t32 using (a) left join t1 as t33 using (a) left join t1 as t34 using (a) left join t1 as t35 using (a) left join t1 as t36 using (a) left join t1 as t37 using (a) left join t1 as t38 using (a) left join t1 as t39 using (a) left join t1 as t40 using (a) left join t1 as t41 using (a) left join t1 as t42 using (a) left join t1 as t43 using (a) left join t1 as t44 using (a) left join t1 as t45 using (a) left join t1 as t46 using (a) left join t1 as t47 using (a) left join t1 as t48 using (a) left join t1 as t49 using (a) left join t1 as t50 using (a) left join t1 as t51 using (a) left join t1 as t52 using (a) left join t1 as t53 using (a) left join t1 as t54 using (a) left join t1 as t55 using (a) left join t1 as t56 using (a) left join t1 as t57 using (a) left join t1 as t58 using (a) left join t1 as t59 using (a) left join t1 as t60 using (a) left join t1 as t61 using (a) left join t1 as t62 using (a) left join t1 as t63 using (a) left join t1 as t64 using (a) left join t1 as t65 using (a); Too many tables. MySQL can only use XX tables in a join drop table t1; CREATE TABLE t1 ( a int(11) NOT NULL, b int(11) NOT NULL, PRIMARY KEY (a,b) ) TYPE=MyISAM; INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(2,3); CREATE TABLE t2 ( a int(11) default NULL ) TYPE=MyISAM; INSERT INTO t2 VALUES (2),(3); SELECT t1.a,t2.a,b FROM t1,t2 WHERE t1.a=t2.a AND (t1.a=1 OR t1.a=2) AND b>=1 AND b<=3; a a b 2 2 3 DROP TABLE t1, t2; CREATE TABLE t1 (d DATE NOT NULL); CREATE TABLE t2 (d DATE NOT NULL); INSERT INTO t1 (d) VALUES ('2001-08-01'),('0000-00-00'); SELECT * FROM t1 LEFT JOIN t2 USING (d) WHERE t2.d IS NULL; d d 2001-08-01 NULL 0000-00-00 NULL SELECT * from t1 WHERE t1.d IS NULL; d 0000-00-00 SELECT * FROM t1 WHERE 1/0 IS NULL; d 2001-08-01 0000-00-00 DROP TABLE t1,t2; CREATE TABLE t1 ( Document_ID varchar(50) NOT NULL default '', Contractor_ID varchar(6) NOT NULL default '', Language_ID char(3) NOT NULL default '', Expiration_Date datetime default NULL, Publishing_Date datetime default NULL, Title text, Column_ID varchar(50) NOT NULL default '', PRIMARY KEY (Language_ID,Document_ID,Contractor_ID) ); INSERT INTO t1 VALUES ('xep80','1','ger','2001-12-31 20:00:00','2001-11-12 10:58:00','Kartenbestellung - jetzt auch online','anle'),('','999998','',NULL,NULL,NULL,''); CREATE TABLE t2 ( Contractor_ID char(6) NOT NULL default '', Language_ID char(3) NOT NULL default '', Document_ID char(50) NOT NULL default '', CanRead char(1) default NULL, Customer_ID int(11) NOT NULL default '0', PRIMARY KEY (Contractor_ID,Language_ID,Document_ID,Customer_ID) ); INSERT INTO t2 VALUES ('5','ger','xep80','1',999999),('1','ger','xep80','1',999999); CREATE TABLE t3 ( Language_ID char(3) NOT NULL default '', Column_ID char(50) NOT NULL default '', Contractor_ID char(6) NOT NULL default '', CanRead char(1) default NULL, Active char(1) default NULL, PRIMARY KEY (Language_ID,Column_ID,Contractor_ID) ); INSERT INTO t3 VALUES ('ger','home','1','1','1'),('ger','Test','1','0','0'),('ger','derclu','1','0','0'),('ger','clubne','1','0','0'),('ger','philos','1','0','0'),('ger','clubko','1','0','0'),('ger','clubim','1','1','1'),('ger','progra','1','0','0'),('ger','progvo','1','0','0'),('ger','progsp','1','0','0'),('ger','progau','1','0','0'),('ger','progku','1','0','0'),('ger','progss','1','0','0'),('ger','nachl','1','0','0'),('ger','mitgli','1','0','0'),('ger','mitsu','1','0','0'),('ger','mitbus','1','0','0'),('ger','ergmar','1','1','1'),('ger','home','4','1','1'),('ger','derclu','4','1','1'),('ger','clubne','4','0','0'),('ger','philos','4','1','1'),('ger','clubko','4','1','1'),('ger','clubim','4','1','1'),('ger','progra','4','1','1'),('ger','progvo','4','1','1'),('ger','progsp','4','1','1'),('ger','progau','4','0','0'),('ger','progku','4','1','1'),('ger','progss','4','1','1'),('ger','nachl','4','1','1'),('ger','mitgli','4','0','0'),('ger','mitsu','4','0','0'),('ger','mitbus','4','0','0'),('ger','ergmar','4','1','1'),('ger','progra2','1','0','0'),('ger','archiv','4','1','1'),('ger','anmeld','4','1','1'),('ger','thema','4','1','1'),('ger','edito','4','1','1'),('ger','madis','4','1','1'),('ger','enma','4','1','1'),('ger','madis','1','1','1'),('ger','enma','1','1','1'),('ger','vorsch','4','0','0'),('ger','veranst','4','0','0'),('ger','anle','4','1','1'),('ger','redak','4','1','1'),('ger','nele','4','1','1'),('ger','aukt','4','1','1'),('ger','callcenter','4','1','1'),('ger','anle','1','0','0'); delete from t1 where Contractor_ID='999998'; insert into t1 (Contractor_ID) Values ('999998'); SELECT DISTINCT COUNT(t1.Title) FROM t1, t2, t3 WHERE t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND t1.Language_ID='ger' AND '2001-12-21 23:14:24' >= Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND t1.Document_ID = t2.Document_ID AND t1.Language_ID = t2.Language_ID AND t1.Contractor_ID = t2.Contractor_ID AND ( t2.Customer_ID = '4' OR t2.Customer_ID = '999999' OR t2.Customer_ID = '1' )AND t2.CanRead = '1' AND t1.Column_ID=t3.Column_ID AND t1.Language_ID=t3.Language_ID AND ( t3.Contractor_ID = '4' OR t3.Contractor_ID = '999999' OR t3.Contractor_ID = '1') AND t3.CanRead='1' AND t3.Active='1'; COUNT(t1.Title) 1 SELECT DISTINCT COUNT(t1.Title) FROM t1, t2, t3 WHERE t1.Document_ID='xep80' AND t1.Contractor_ID='1' AND t1.Language_ID='ger' AND '2001-12-21 23:14:24' >= Publishing_Date AND '2001-12-21 23:14:24' <= Expiration_Date AND t1.Document_ID = t2.Document_ID AND t1.Language_ID = t2.Language_ID AND t1.Contractor_ID = t2.Contractor_ID AND ( t2.Customer_ID = '4' OR t2.Customer_ID = '999999' OR t2.Customer_ID = '1' )AND t2.CanRead = '1' AND t1.Column_ID=t3.Column_ID AND t1.Language_ID=t3.Language_ID AND ( t3.Contractor_ID = '4' OR t3.Contractor_ID = '999999' OR t3.Contractor_ID = '1') AND t3.CanRead='1' AND t3.Active='1'; COUNT(t1.Title) 1 drop table t1,t2,t3; CREATE TABLE t1 ( t1_id int(11) default NULL, t2_id int(11) default NULL, type enum('Cost','Percent') default NULL, cost_unit enum('Cost','Unit') default NULL, min_value double default NULL, max_value double default NULL, t3_id int(11) default NULL, item_id int(11) default NULL ) TYPE=MyISAM; INSERT INTO t1 VALUES (12,5,'Percent','Cost',-1,0,-1,-1),(14,4,'Percent','Cost',-1,0,-1,-1),(18,5,'Percent','Cost',-1,0,-1,-1),(19,4,'Percent','Cost',-1,0,-1,-1),(20,5,'Percent','Cost',100,-1,22,291),(21,5,'Percent','Cost',100,-1,18,291),(22,1,'Percent','Cost',100,-1,6,291),(23,1,'Percent','Cost',100,-1,21,291),(24,1,'Percent','Cost',100,-1,9,291),(25,1,'Percent','Cost',100,-1,4,291),(26,1,'Percent','Cost',100,-1,20,291),(27,4,'Percent','Cost',100,-1,7,202),(28,1,'Percent','Cost',50,-1,-1,137),(29,2,'Percent','Cost',100,-1,4,354),(30,2,'Percent','Cost',100,-1,9,137),(93,2,'Cost','Cost',-1,10000000,-1,-1); CREATE TABLE t2 ( id int(10) unsigned NOT NULL auto_increment, name varchar(255) default NULL, PRIMARY KEY (id) ) TYPE=MyISAM; INSERT INTO t2 VALUES (1,'s1'),(2,'s2'),(3,'s3'),(4,'s4'),(5,'s5'); select t1.*, t2.* from t1, t2 where t2.id=t1.t2_id limit 2; t1_id t2_id type cost_unit min_value max_value t3_id item_id id name 22 1 Percent Cost 100 -1 6 291 1 s1 23 1 Percent Cost 100 -1 21 291 1 s1 drop table t1,t2;