~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1,t2,t3,t4,t11;
2
drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa;
3
CREATE TABLE t1 (
4
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
5
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
6
);
7
INSERT INTO t1 VALUES (9410,9412);
8
select period from t1;
9
period
10
9410
11
select * from t1;
12
Period	Varor_period
13
9410	9412
14
select t1.* from t1;
15
Period	Varor_period
16
9410	9412
17
CREATE TABLE t2 (
18
auto int not null auto_increment,
19
fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL,
20
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
21
fld3 char(30) DEFAULT '' NOT NULL,
22
fld4 char(35) DEFAULT '' NOT NULL,
23
fld5 char(35) DEFAULT '' NOT NULL,
24
fld6 char(4) DEFAULT '' NOT NULL,
25
UNIQUE fld1 (fld1),
26
KEY fld3 (fld3),
27
PRIMARY KEY (auto)
28
);
29
select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%";
30
fld3
31
imaginable
32
select fld3 from t2 where fld3 like "%cultivation" ;
33
fld3
34
cultivation
35
select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3;
36
fld3	companynr
37
concoct	58
38
druggists	58
39
engrossing	58
40
Eurydice	58
41
exclaimers	58
42
ferociousness	58
43
hopelessness	58
44
Huey	58
45
imaginable	58
46
judges	58
47
merging	58
48
ostrich	58
49
peering	58
50
Phelps	58
51
presumes	58
52
Ruth	58
53
sentences	58
54
Shylock	58
55
straggled	58
56
synergy	58
57
thanking	58
58
tying	58
59
unlocks	58
60
select fld3,companynr from t2 where companynr = 58 order by fld3;
61
fld3	companynr
62
concoct	58
63
druggists	58
64
engrossing	58
65
Eurydice	58
66
exclaimers	58
67
ferociousness	58
68
hopelessness	58
69
Huey	58
70
imaginable	58
71
judges	58
72
merging	58
73
ostrich	58
74
peering	58
75
Phelps	58
76
presumes	58
77
Ruth	58
78
sentences	58
79
Shylock	58
80
straggled	58
81
synergy	58
82
thanking	58
83
tying	58
84
unlocks	58
85
select fld3 from t2 order by fld3 desc limit 10;
86
fld3
87
youthfulness
88
yelped
89
Wotan
90
workers
91
Witt
92
witchcraft
93
Winsett
94
Willy
95
willed
96
wildcats
97
select fld3 from t2 order by fld3 desc limit 5;
98
fld3
99
youthfulness
100
yelped
101
Wotan
102
workers
103
Witt
104
select fld3 from t2 order by fld3 desc limit 5,5;
105
fld3
106
witchcraft
107
Winsett
108
Willy
109
willed
110
wildcats
111
select t2.fld3 from t2 where fld3 = 'honeysuckle';
112
fld3
113
honeysuckle
114
select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_';
115
fld3
116
honeysuckle
117
select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_';
118
fld3
119
honeysuckle
120
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%';
121
fld3
122
honeysuckle
123
select t2.fld3 from t2 where fld3 LIKE 'h%le';
124
fld3
125
honeysuckle
126
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_';
127
fld3
128
select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%';
129
fld3
130
select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
131
fld3
132
honeysuckle
133
honoring
134
select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3;
135
fld1	fld3
136
148504	Colombo
137
068305	Colombo
138
000000	nondecreasing
139
select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes';
140
fld1	fld3
141
232605	appendixes
142
1232605	appendixes
143
1232606	appendixes
144
1232607	appendixes
145
1232608	appendixes
146
1232609	appendixes
147
select fld1 from t2 where fld1=250501 or fld1="250502";
148
fld1
149
250501
150
250502
151
select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
152
fld1
153
250501
154
250502
155
250505
156
250601
157
select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%';
158
fld1	fld3
159
012001	flanking
160
013602	foldout
161
013606	fingerings
162
018007	fanatic
163
018017	featherweight
164
018054	fetters
165
018103	flint
166
018104	flopping
167
036002	funereal
168
038017	fetched
169
038205	firearm
170
058004	Fenton
171
088303	feminine
172
186002	freakish
173
188007	flurried
174
188505	fitting
175
198006	furthermore
176
202301	Fitzpatrick
177
208101	fiftieth
178
208113	freest
179
218008	finishers
180
218022	feed
181
218401	faithful
182
226205	foothill
183
226209	furnishings
184
228306	forthcoming
185
228311	fated
186
231315	freezes
187
232102	forgivably
188
238007	filial
189
238008	fixedly
190
select fld3 from t2 where fld3 like "L%" and fld3 = "ok";
191
fld3
192
select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly");
193
fld3
194
Chantilly
195
select fld1,fld3 from t2 where fld1 like "25050%";
196
fld1	fld3
197
250501	poisoning
198
250502	Iraqis
199
250503	heaving
200
250504	population
201
250505	bomb
202
select fld1,fld3 from t2 where fld1 like "25050_";
203
fld1	fld3
204
250501	poisoning
205
250502	Iraqis
206
250503	heaving
207
250504	population
208
250505	bomb
209
select distinct companynr from t2;
210
companynr
211
00
212
37
213
36
214
50
215
58
216
29
217
40
218
53
219
65
220
41
221
34
222
68
223
select distinct companynr from t2 order by companynr;
224
companynr
225
00
226
29
227
34
228
36
229
37
230
40
231
41
232
50
233
53
234
58
235
65
236
68
237
select distinct companynr from t2 order by companynr desc;
238
companynr
239
68
240
65
241
58
242
53
243
50
244
41
245
40
246
37
247
36
248
34
249
29
250
00
251
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
252
fld3	period
201 by Brian Aker
Convert default engine to Innodb
253
overlay	9410
254
offload	9410
1 by brian
clean slate
255
obliterates	9410
201 by Brian Aker
Convert default engine to Innodb
256
overestimating	9410
1 by brian
clean slate
257
opaquely	9410
258
organizer	9410
259
select distinct fld3 from t2 where companynr = 34 order by fld3;
260
fld3
261
absentee
262
accessed
263
ahead
264
alphabetic
265
Asiaticizations
266
attitude
267
aye
268
bankruptcies
269
belays
270
Blythe
271
bomb
272
boulevard
273
bulldozes
274
cannot
275
caressing
276
charcoal
277
checksumming
278
chess
279
clubroom
280
colorful
281
cosy
282
creator
283
crying
284
Darius
285
diffusing
286
duality
287
Eiffel
288
Epiphany
289
Ernestine
290
explorers
291
exterminated
292
famine
293
forked
294
Gershwins
295
heaving
296
Hodges
297
Iraqis
298
Italianization
299
Lagos
300
landslide
301
libretto
302
Majorca
303
mastering
304
narrowed
305
occurred
306
offerers
307
Palestine
308
Peruvianizes
309
pharmaceutic
310
poisoning
311
population
312
Pygmalion
313
rats
314
realest
315
recording
316
regimented
317
retransmitting
318
reviver
319
rouses
320
scars
321
sicker
322
sleepwalk
323
stopped
324
sugars
325
translatable
326
uncles
327
unexpected
328
uprisings
329
versatility
330
vest
331
select distinct fld3 from t2 limit 10;
332
fld3
201 by Brian Aker
Convert default engine to Innodb
333
Omaha
334
breaking
335
Romans
336
intercepted
337
bewilderingly
338
astound
339
admonishing
340
sumac
341
flanking
342
combed
1 by brian
clean slate
343
select distinct fld3 from t2 having fld3 like "A%" limit 10;
344
fld3
345
abates
346
abiding
347
Abraham
348
abrogating
349
absentee
350
abut
351
accessed
352
accruing
353
accumulating
354
accuracies
355
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
356
substring(fld3,1,3)
357
aba
358
abi
359
Abr
360
abs
361
abu
362
acc
363
acq
364
acu
365
Ade
366
adj
367
Adl
368
adm
369
Ado
370
ads
371
adv
372
aer
373
aff
374
afi
375
afl
376
afo
377
agi
378
ahe
379
aim
380
air
381
Ald
382
alg
383
ali
384
all
385
alp
386
alr
387
ama
388
ame
389
amm
390
ana
391
and
392
ane
393
Ang
394
ani
395
Ann
396
Ant
397
api
398
app
399
aqu
400
Ara
401
arc
402
Arm
403
arr
404
Art
405
Asi
406
ask
407
asp
408
ass
409
ast
410
att
411
aud
412
Aug
413
aut
414
ave
415
avo
416
awe
417
aye
418
Azt
419
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
420
a
421
aba
422
abi
201 by Brian Aker
Convert default engine to Innodb
423
abr
1 by brian
clean slate
424
abs
425
abu
426
acc
427
acq
428
acu
429
Ade
430
adj
431
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
432
substring(fld3,1,3)
433
aba
434
abi
435
Abr
436
abs
437
abu
438
acc
439
acq
440
acu
441
Ade
442
adj
443
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
444
a
201 by Brian Aker
Convert default engine to Innodb
445
ast
446
adm
447
ann
448
agi
449
afi
450
amm
451
Aug
452
aud
453
att
454
Ado
1 by brian
clean slate
455
create table t3 (
456
period    int not null,
457
name      char(32) not null,
458
companynr int not null,
459
price     double(11,0),
460
price2     double(11,0),
461
key (period),
462
key (name)
463
);
464
create temporary table tmp engine = myisam select * from t3;
465
insert into t3 select * from tmp;
466
insert into tmp select * from t3;
467
insert into t3 select * from tmp;
468
insert into tmp select * from t3;
469
insert into t3 select * from tmp;
470
insert into tmp select * from t3;
471
insert into t3 select * from tmp;
472
insert into tmp select * from t3;
473
insert into t3 select * from tmp;
474
insert into tmp select * from t3;
475
insert into t3 select * from tmp;
476
insert into tmp select * from t3;
477
insert into t3 select * from tmp;
478
insert into tmp select * from t3;
479
insert into t3 select * from tmp;
480
insert into tmp select * from t3;
481
insert into t3 select * from tmp;
482
alter table t3 add t2nr int not null auto_increment primary key first;
483
drop table tmp;
484
SET SQL_BIG_TABLES=1;
485
select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10;
486
namn
487
Abraham Abraham
488
abrogating abrogating
489
admonishing admonishing
490
Adolph Adolph
491
afield afield
492
aging aging
493
ammonium ammonium
494
analyzable analyzable
495
animals animals
496
animized animized
497
SET SQL_BIG_TABLES=0;
498
select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10;
499
concat(fld3," ",fld3)
500
Abraham Abraham
501
abrogating abrogating
502
admonishing admonishing
503
Adolph Adolph
504
afield afield
505
aging aging
506
ammonium ammonium
507
analyzable analyzable
508
animals animals
509
animized animized
510
select distinct fld5 from t2 limit 10;
511
fld5
512
neat
513
Steinberg
514
jarring
515
tinily
516
balled
517
persist
518
attainments
519
fanatic
520
measures
521
rightfulness
522
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
523
fld3	count(*)
524
affixed	1
525
and	1
526
annoyers	1
527
Anthony	1
528
assayed	1
529
assurers	1
530
attendants	1
531
bedlam	1
532
bedpost	1
533
boasted	1
534
SET SQL_BIG_TABLES=1;
535
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
536
fld3	count(*)
537
affixed	1
538
and	1
539
annoyers	1
540
Anthony	1
541
assayed	1
542
assurers	1
543
attendants	1
544
bedlam	1
545
bedpost	1
546
boasted	1
547
SET SQL_BIG_TABLES=0;
548
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
549
fld3	repeat("a",length(fld3))	count(*)
550
circus	aaaaaa	1
551
cited	aaaaa	1
552
Colombo	aaaaaaa	1
553
congresswoman	aaaaaaaaaaaaa	1
554
contrition	aaaaaaaaaa	1
555
corny	aaaaa	1
556
cultivation	aaaaaaaaaaa	1
557
definiteness	aaaaaaaaaaaa	1
558
demultiplex	aaaaaaaaaaa	1
559
disappointing	aaaaaaaaaaaaa	1
560
select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2;
561
companynr	rtrim(space(512+companynr))
562
37	
563
78	
564
101	
565
154	
566
311	
567
447	
568
512	
569
select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3;
570
fld3
571
select period from t1;
572
period
573
9410
574
select period from t1 where period=1900;
575
period
576
select fld3,period from t1,t2 where fld1 = 011401 order by period;
577
fld3	period
578
breaking	9410
579
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
580
fld3	period
581
breaking	1001
582
select fld3,period from t2,t1 where companynr*10 = 37*10;
583
fld3	period
584
breaking	9410
585
Romans	9410
586
intercepted	9410
587
bewilderingly	9410
588
astound	9410
589
admonishing	9410
590
sumac	9410
591
flanking	9410
592
combed	9410
593
subjective	9410
594
scatterbrain	9410
595
Eulerian	9410
596
Kane	9410
597
overlay	9410
598
perturb	9410
599
goblins	9410
600
annihilates	9410
601
Wotan	9410
602
snatching	9410
603
concludes	9410
604
laterally	9410
605
yelped	9410
606
grazing	9410
607
Baird	9410
608
celery	9410
609
misunderstander	9410
610
handgun	9410
611
foldout	9410
612
mystic	9410
613
succumbed	9410
614
Nabisco	9410
615
fingerings	9410
616
aging	9410
617
afield	9410
618
ammonium	9410
619
boat	9410
620
intelligibility	9410
621
Augustine	9410
622
teethe	9410
623
dreaded	9410
624
scholastics	9410
625
audiology	9410
626
wallet	9410
627
parters	9410
628
eschew	9410
629
quitter	9410
630
neat	9410
631
Steinberg	9410
632
jarring	9410
633
tinily	9410
634
balled	9410
635
persist	9410
636
attainments	9410
637
fanatic	9410
638
measures	9410
639
rightfulness	9410
640
capably	9410
641
impulsive	9410
642
starlet	9410
643
terminators	9410
644
untying	9410
645
announces	9410
646
featherweight	9410
647
pessimist	9410
648
daughter	9410
649
decliner	9410
650
lawgiver	9410
651
stated	9410
652
readable	9410
653
attrition	9410
654
cascade	9410
655
motors	9410
656
interrogate	9410
657
pests	9410
658
stairway	9410
659
dopers	9410
660
testicle	9410
661
Parsifal	9410
662
leavings	9410
663
postulation	9410
664
squeaking	9410
665
contrasted	9410
666
leftover	9410
667
whiteners	9410
668
erases	9410
669
Punjab	9410
670
Merritt	9410
671
Quixotism	9410
672
sweetish	9410
673
dogging	9410
674
scornfully	9410
675
bellow	9410
676
bills	9410
677
cupboard	9410
678
sureties	9410
679
puddings	9410
680
fetters	9410
681
bivalves	9410
682
incurring	9410
683
Adolph	9410
684
pithed	9410
685
Miles	9410
686
trimmings	9410
687
tragedies	9410
688
skulking	9410
689
flint	9410
690
flopping	9410
691
relaxing	9410
692
offload	9410
693
suites	9410
694
lists	9410
695
animized	9410
696
multilayer	9410
697
standardizes	9410
698
Judas	9410
699
vacuuming	9410
700
dentally	9410
701
humanness	9410
702
inch	9410
703
Weissmuller	9410
704
irresponsibly	9410
705
luckily	9410
706
culled	9410
707
medical	9410
708
bloodbath	9410
709
subschema	9410
710
animals	9410
711
Micronesia	9410
712
repetitions	9410
713
Antares	9410
714
ventilate	9410
715
pityingly	9410
716
interdependent	9410
717
Graves	9410
718
neonatal	9410
719
chafe	9410
720
honoring	9410
721
realtor	9410
722
elite	9410
723
funereal	9410
724
abrogating	9410
725
sorters	9410
726
Conley	9410
727
lectured	9410
728
Abraham	9410
729
Hawaii	9410
730
cage	9410
731
hushes	9410
732
Simla	9410
733
reporters	9410
734
Dutchman	9410
735
descendants	9410
736
groupings	9410
737
dissociate	9410
738
coexist	9410
739
Beebe	9410
740
Taoism	9410
741
Connally	9410
742
fetched	9410
743
checkpoints	9410
744
rusting	9410
745
galling	9410
746
obliterates	9410
747
traitor	9410
748
resumes	9410
749
analyzable	9410
750
terminator	9410
751
gritty	9410
752
firearm	9410
753
minima	9410
754
Selfridge	9410
755
disable	9410
756
witchcraft	9410
757
betroth	9410
758
Manhattanize	9410
759
imprint	9410
760
peeked	9410
761
swelling	9410
762
interrelationships	9410
763
riser	9410
764
Gandhian	9410
765
peacock	9410
766
bee	9410
767
kanji	9410
768
dental	9410
769
scarf	9410
770
chasm	9410
771
insolence	9410
772
syndicate	9410
773
alike	9410
774
imperial	9410
775
convulsion	9410
776
railway	9410
777
validate	9410
778
normalizes	9410
779
comprehensive	9410
780
chewing	9410
781
denizen	9410
782
schemer	9410
783
chronicle	9410
784
Kline	9410
785
Anatole	9410
786
partridges	9410
787
brunch	9410
788
recruited	9410
789
dimensions	9410
790
Chicana	9410
791
announced	9410
792
praised	9410
793
employing	9410
794
linear	9410
795
quagmire	9410
796
western	9410
797
relishing	9410
798
serving	9410
799
scheduling	9410
800
lore	9410
801
eventful	9410
802
arteriole	9410
803
disentangle	9410
804
cured	9410
805
Fenton	9410
806
avoidable	9410
807
drains	9410
808
detectably	9410
809
husky	9410
810
impelling	9410
811
undoes	9410
812
evened	9410
813
squeezes	9410
814
destroyer	9410
815
rudeness	9410
816
beaner	9410
817
boorish	9410
818
Everhart	9410
819
encompass	9410
820
mushrooms	9410
821
Alison	9410
822
externally	9410
823
pellagra	9410
824
cult	9410
825
creek	9410
826
Huffman	9410
827
Majorca	9410
828
governing	9410
829
gadfly	9410
830
reassigned	9410
831
intentness	9410
832
craziness	9410
833
psychic	9410
834
squabbled	9410
835
burlesque	9410
836
capped	9410
837
extracted	9410
838
DiMaggio	9410
839
exclamation	9410
840
subdirectory	9410
841
Gothicism	9410
842
feminine	9410
843
metaphysically	9410
844
sanding	9410
845
Miltonism	9410
846
freakish	9410
847
index	9410
848
straight	9410
849
flurried	9410
850
denotative	9410
851
coming	9410
852
commencements	9410
853
gentleman	9410
854
gifted	9410
855
Shanghais	9410
856
sportswriting	9410
857
sloping	9410
858
navies	9410
859
leaflet	9410
860
shooter	9410
861
Joplin	9410
862
babies	9410
863
assails	9410
864
admiring	9410
865
swaying	9410
866
Goldstine	9410
867
fitting	9410
868
Norwalk	9410
869
analogy	9410
870
deludes	9410
871
cokes	9410
872
Clayton	9410
873
exhausts	9410
874
causality	9410
875
sating	9410
876
icon	9410
877
throttles	9410
878
communicants	9410
879
dehydrate	9410
880
priceless	9410
881
publicly	9410
882
incidentals	9410
883
commonplace	9410
884
mumbles	9410
885
furthermore	9410
886
cautioned	9410
887
parametrized	9410
888
registration	9410
889
sadly	9410
890
positioning	9410
891
babysitting	9410
892
eternal	9410
893
hoarder	9410
894
congregates	9410
895
rains	9410
896
workers	9410
897
sags	9410
898
unplug	9410
899
garage	9410
900
boulder	9410
901
specifics	9410
902
Teresa	9410
903
Winsett	9410
904
convenient	9410
905
buckboards	9410
906
amenities	9410
907
resplendent	9410
908
sews	9410
909
participated	9410
910
Simon	9410
911
certificates	9410
912
Fitzpatrick	9410
913
Evanston	9410
914
misted	9410
915
textures	9410
916
save	9410
917
count	9410
918
rightful	9410
919
chaperone	9410
920
Lizzy	9410
921
clenched	9410
922
effortlessly	9410
923
accessed	9410
924
beaters	9410
925
Hornblower	9410
926
vests	9410
927
indulgences	9410
928
infallibly	9410
929
unwilling	9410
930
excrete	9410
931
spools	9410
932
crunches	9410
933
overestimating	9410
934
ineffective	9410
935
humiliation	9410
936
sophomore	9410
937
star	9410
938
rifles	9410
939
dialysis	9410
940
arriving	9410
941
indulge	9410
942
clockers	9410
943
languages	9410
944
Antarctica	9410
945
percentage	9410
946
ceiling	9410
947
specification	9410
948
regimented	9410
949
ciphers	9410
950
pictures	9410
951
serpents	9410
952
allot	9410
953
realized	9410
954
mayoral	9410
955
opaquely	9410
956
hostess	9410
957
fiftieth	9410
958
incorrectly	9410
959
decomposition	9410
960
stranglings	9410
961
mixture	9410
962
electroencephalography	9410
963
similarities	9410
964
charges	9410
965
freest	9410
966
Greenberg	9410
967
tinting	9410
968
expelled	9410
969
warm	9410
970
smoothed	9410
971
deductions	9410
972
Romano	9410
973
bitterroot	9410
974
corset	9410
975
securing	9410
976
environing	9410
977
cute	9410
978
Crays	9410
979
heiress	9410
980
inform	9410
981
avenge	9410
982
universals	9410
983
Kinsey	9410
984
ravines	9410
985
bestseller	9410
986
equilibrium	9410
987
extents	9410
988
relatively	9410
989
pressure	9410
990
critiques	9410
991
befouled	9410
992
rightfully	9410
993
mechanizing	9410
994
Latinizes	9410
995
timesharing	9410
996
Aden	9410
997
embassies	9410
998
males	9410
999
shapelessly	9410
1000
mastering	9410
1001
Newtonian	9410
1002
finishers	9410
1003
abates	9410
1004
teem	9410
1005
kiting	9410
1006
stodgy	9410
1007
feed	9410
1008
guitars	9410
1009
airships	9410
1010
store	9410
1011
denounces	9410
1012
Pyle	9410
1013
Saxony	9410
1014
serializations	9410
1015
Peruvian	9410
1016
taxonomically	9410
1017
kingdom	9410
1018
stint	9410
1019
Sault	9410
1020
faithful	9410
1021
Ganymede	9410
1022
tidiness	9410
1023
gainful	9410
1024
contrary	9410
1025
Tipperary	9410
1026
tropics	9410
1027
theorizers	9410
1028
renew	9410
1029
already	9410
1030
terminal	9410
1031
Hegelian	9410
1032
hypothesizer	9410
1033
warningly	9410
1034
journalizing	9410
1035
nested	9410
1036
Lars	9410
1037
saplings	9410
1038
foothill	9410
1039
labeled	9410
1040
imperiously	9410
1041
reporters	9410
1042
furnishings	9410
1043
precipitable	9410
1044
discounts	9410
1045
excises	9410
1046
Stalin	9410
1047
despot	9410
1048
ripeness	9410
1049
Arabia	9410
1050
unruly	9410
1051
mournfulness	9410
1052
boom	9410
1053
slaughter	9410
1054
Sabine	9410
1055
handy	9410
1056
rural	9410
1057
organizer	9410
1058
shipyard	9410
1059
civics	9410
1060
inaccuracy	9410
1061
rules	9410
1062
juveniles	9410
1063
comprised	9410
1064
investigations	9410
1065
stabilizes	9410
1066
seminaries	9410
1067
Hunter	9410
1068
sporty	9410
1069
test	9410
1070
weasels	9410
1071
CERN	9410
1072
tempering	9410
1073
afore	9410
1074
Galatean	9410
1075
techniques	9410
1076
error	9410
1077
veranda	9410
1078
severely	9410
1079
Cassites	9410
1080
forthcoming	9410
1081
guides	9410
1082
vanish	9410
1083
lied	9410
1084
sawtooth	9410
1085
fated	9410
1086
gradually	9410
1087
widens	9410
1088
preclude	9410
1089
evenhandedly	9410
1090
percentage	9410
1091
disobedience	9410
1092
humility	9410
1093
gleaning	9410
1094
petted	9410
1095
bloater	9410
1096
minion	9410
1097
marginal	9410
1098
apiary	9410
1099
measures	9410
1100
precaution	9410
1101
repelled	9410
1102
primary	9410
1103
coverings	9410
1104
Artemia	9410
1105
navigate	9410
1106
spatial	9410
1107
Gurkha	9410
1108
meanwhile	9410
1109
Melinda	9410
1110
Butterfield	9410
1111
Aldrich	9410
1112
previewing	9410
1113
glut	9410
1114
unaffected	9410
1115
inmate	9410
1116
mineral	9410
1117
impending	9410
1118
meditation	9410
1119
ideas	9410
1120
miniaturizes	9410
1121
lewdly	9410
1122
title	9410
1123
youthfulness	9410
1124
creak	9410
1125
Chippewa	9410
1126
clamored	9410
1127
freezes	9410
1128
forgivably	9410
1129
reduce	9410
1130
McGovern	9410
1131
Nazis	9410
1132
epistle	9410
1133
socializes	9410
1134
conceptions	9410
1135
Kevin	9410
1136
uncovering	9410
1137
chews	9410
1138
appendixes	9410
1139
raining	9410
1140
infest	9410
1141
compartment	9410
1142
minting	9410
1143
ducks	9410
1144
roped	9410
1145
waltz	9410
1146
Lillian	9410
1147
repressions	9410
1148
chillingly	9410
1149
noncritical	9410
1150
lithograph	9410
1151
spongers	9410
1152
parenthood	9410
1153
posed	9410
1154
instruments	9410
1155
filial	9410
1156
fixedly	9410
1157
relives	9410
1158
Pandora	9410
1159
watering	9410
1160
ungrateful	9410
1161
secures	9410
1162
poison	9410
1163
dusted	9410
1164
encompasses	9410
1165
presentation	9410
1166
Kantian	9410
201 by Brian Aker
Convert default engine to Innodb
1167
appendixes	9410
1168
appendixes	9410
1169
appendixes	9410
1170
appendixes	9410
1171
appendixes	9410
1 by brian
clean slate
1172
select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price;
1173
fld3	period	price	price2
1174
admonishing	1002	28357832	8723648
1175
analyzable	1002	28357832	8723648
1176
annihilates	1001	5987435	234724
1177
Antares	1002	28357832	8723648
1178
astound	1001	5987435	234724
1179
audiology	1001	5987435	234724
1180
Augustine	1002	28357832	8723648
1181
Baird	1002	28357832	8723648
1182
bewilderingly	1001	5987435	234724
1183
breaking	1001	5987435	234724
1184
Conley	1001	5987435	234724
1185
dentally	1002	28357832	8723648
1186
dissociate	1002	28357832	8723648
1187
elite	1001	5987435	234724
1188
eschew	1001	5987435	234724
1189
Eulerian	1001	5987435	234724
1190
flanking	1001	5987435	234724
1191
foldout	1002	28357832	8723648
1192
funereal	1002	28357832	8723648
1193
galling	1002	28357832	8723648
1194
Graves	1001	5987435	234724
1195
grazing	1001	5987435	234724
1196
groupings	1001	5987435	234724
1197
handgun	1001	5987435	234724
1198
humility	1002	28357832	8723648
1199
impulsive	1002	28357832	8723648
1200
inch	1001	5987435	234724
1201
intelligibility	1001	5987435	234724
1202
jarring	1001	5987435	234724
1203
lawgiver	1001	5987435	234724
1204
lectured	1002	28357832	8723648
1205
Merritt	1002	28357832	8723648
1206
neonatal	1001	5987435	234724
1207
offload	1002	28357832	8723648
1208
parters	1002	28357832	8723648
1209
pityingly	1002	28357832	8723648
1210
puddings	1002	28357832	8723648
1211
Punjab	1001	5987435	234724
1212
quitter	1002	28357832	8723648
1213
realtor	1001	5987435	234724
1214
relaxing	1001	5987435	234724
1215
repetitions	1001	5987435	234724
1216
resumes	1001	5987435	234724
1217
Romans	1002	28357832	8723648
1218
rusting	1001	5987435	234724
1219
scholastics	1001	5987435	234724
1220
skulking	1002	28357832	8723648
1221
stated	1002	28357832	8723648
1222
suites	1002	28357832	8723648
1223
sureties	1001	5987435	234724
1224
testicle	1002	28357832	8723648
1225
tinily	1002	28357832	8723648
1226
tragedies	1001	5987435	234724
1227
trimmings	1001	5987435	234724
1228
vacuuming	1001	5987435	234724
1229
ventilate	1001	5987435	234724
1230
wallet	1001	5987435	234724
1231
Weissmuller	1002	28357832	8723648
1232
Wotan	1002	28357832	8723648
1233
select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37;
1234
fld1	fld3	period	price	price2
1235
018201	relaxing	1001	5987435	234724
1236
018601	vacuuming	1001	5987435	234724
1237
018801	inch	1001	5987435	234724
1238
018811	repetitions	1001	5987435	234724
1239
create table t4 (
1240
companynr tinyint(2) unsigned zerofill NOT NULL default '00',
1241
companyname char(30) NOT NULL default '',
1242
PRIMARY KEY (companynr),
1243
UNIQUE KEY companyname(companyname)
1244
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
1245
select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
1246
companynr	companyname
1247
00	Unknown
1248
29	company 1
1249
34	company 2
1250
36	company 3
1251
37	company 4
1252
40	company 5
1253
41	company 6
1254
50	company 11
1255
53	company 7
1256
58	company 8
1257
65	company 9
1258
68	company 10
1259
select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
1260
companynr	companyname
1261
00	Unknown
1262
29	company 1
1263
34	company 2
1264
36	company 3
1265
37	company 4
1266
40	company 5
1267
41	company 6
1268
50	company 11
1269
53	company 7
1270
58	company 8
1271
65	company 9
1272
68	company 10
1273
select * from t1,t1 t12;
1274
Period	Varor_period	Period	Varor_period
1275
9410	9412	9410	9412
1276
select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505;
1277
fld1	fld1
1278
250501	250501
1279
250502	250501
1280
250503	250501
1281
250504	250501
1282
250505	250501
1283
250501	250502
1284
250502	250502
1285
250503	250502
1286
250504	250502
1287
250505	250502
1288
250501	250503
1289
250502	250503
1290
250503	250503
1291
250504	250503
1292
250505	250503
1293
250501	250504
1294
250502	250504
1295
250503	250504
1296
250504	250504
1297
250505	250504
1298
250501	250505
1299
250502	250505
1300
250503	250505
1301
250504	250505
1302
250505	250505
1303
insert into t2 (fld1, companynr) values (999999,99);
1304
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1305
companynr	companyname
1306
99	NULL
1307
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
1308
count(*)
1309
1199
1310
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1311
companynr	companyname
1312
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
1313
count(*)
1314
1200
1315
delete from t2 where fld1=999999;
1316
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
1317
companynr	companynr
1318
37	36
1319
41	40
1320
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;
1321
fld1	companynr	fld3	period
1322
038008	37	reporters	1008
1323
038208	37	Selfridge	1008
1324
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
1325
fld1	companynr	fld3	period
1326
038008	37	reporters	1008
1327
038208	37	Selfridge	1008
1328
select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009;
1329
fld1	companynr	fld3	period
1330
038008	37	reporters	1008
1331
038208	37	Selfridge	1008
1332
select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909);
1333
period
1334
9410
1335
select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6)));
1336
period
1337
9410
1338
select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1;
1339
fld1
1340
250501
1341
250502
1342
250503
1343
250505
1344
select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606);
1345
fld1
1346
250502
1347
250503
1348
select fld1 from t2 where fld1 between 250502 and 250504;
1349
fld1
1350
250502
1351
250503
1352
250504
1353
select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ;
1354
fld3
1355
label
1356
labeled
1357
labeled
1358
landslide
1359
laterally
1360
leaflet
1361
lewdly
1362
Lillian
1363
luckily
1364
select count(*) from t1;
1365
count(*)
1366
1
1367
select companynr,count(*),sum(fld1) from t2 group by companynr;
1368
companynr	count(*)	sum(fld1)
1369
00	82	10355753
1370
29	95	14473298
1371
34	70	17788966
1372
36	215	22786296
1373
37	588	83602098
1374
40	37	6618386
1375
41	52	12816335
1376
50	11	1595438
1377
53	4	793210
1378
58	23	2254293
1379
65	10	2284055
1380
68	12	3097288
1381
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1382
companynr	count(*)
1383
68	12
1384
65	10
1385
58	23
1386
53	4
1387
50	11
1388
select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1389
count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
1390
70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
1391
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
1392
companynr	count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
1393
00	82	Anthony	windmills	10355753	126289.6707	115550.9757	13352027981.7087
1394
29	95	abut	wetness	14473298	152350.5053	8368.5480	70032594.9026
1395
34	70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
1396
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1397
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
1398
37	1	1	5987435	5987435	5987435	5987435.0000
1399
37	2	1	28357832	28357832	28357832	28357832.0000
1400
37	3	1	39654943	39654943	39654943	39654943.0000
1401
37	11	1	5987435	5987435	5987435	5987435.0000
1402
37	12	1	28357832	28357832	28357832	28357832.0000
1403
37	13	1	39654943	39654943	39654943	39654943.0000
1404
37	21	1	5987435	5987435	5987435	5987435.0000
1405
37	22	1	28357832	28357832	28357832	28357832.0000
1406
37	23	1	39654943	39654943	39654943	39654943.0000
1407
37	31	1	5987435	5987435	5987435	5987435.0000
1408
select /*! SQL_SMALL_RESULT */ companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1409
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
1410
37	1	1	5987435	5987435	5987435	5987435.0000
1411
37	2	1	28357832	28357832	28357832	28357832.0000
1412
37	3	1	39654943	39654943	39654943	39654943.0000
1413
37	11	1	5987435	5987435	5987435	5987435.0000
1414
37	12	1	28357832	28357832	28357832	28357832.0000
1415
37	13	1	39654943	39654943	39654943	39654943.0000
1416
37	21	1	5987435	5987435	5987435	5987435.0000
1417
37	22	1	28357832	28357832	28357832	28357832.0000
1418
37	23	1	39654943	39654943	39654943	39654943.0000
1419
37	31	1	5987435	5987435	5987435	5987435.0000
1420
select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ;
1421
companynr	count(price)	sum(price)	min(price)	max(price)	avg(price)
1422
37	12543	309394878010	5987435	39654943	24666736.6667
1423
78	8362	414611089292	726498	98439034	49582766.0000
1424
101	4181	3489454238	834598	834598	834598.0000
1425
154	4181	4112197254950	983543950	983543950	983543950.0000
1426
311	4181	979599938	234298	234298	234298.0000
1427
447	4181	9929180954	2374834	2374834	2374834.0000
1428
512	4181	3288532102	786542	786542	786542.0000
1429
select distinct mod(companynr,10) from t4 group by companynr;
1430
mod(companynr,10)
1431
0
1432
9
1433
4
1434
6
1435
7
1436
1
1437
3
1438
8
1439
5
1440
select distinct 1 from t4 group by companynr;
1441
1
1442
1
1443
select count(distinct fld1) from t2;
1444
count(distinct fld1)
1445
1199
1446
select companynr,count(distinct fld1) from t2 group by companynr;
1447
companynr	count(distinct fld1)
1448
00	82
1449
29	95
1450
34	70
1451
36	215
1452
37	588
1453
40	37
1454
41	52
1455
50	11
1456
53	4
1457
58	23
1458
65	10
1459
68	12
1460
select companynr,count(*) from t2 group by companynr;
1461
companynr	count(*)
1462
00	82
1463
29	95
1464
34	70
1465
36	215
1466
37	588
1467
40	37
1468
41	52
1469
50	11
1470
53	4
1471
58	23
1472
65	10
1473
68	12
1474
select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr;
1475
companynr	count(distinct concat(fld1,repeat(65,1000)))
1476
00	82
1477
29	95
1478
34	70
1479
36	215
1480
37	588
1481
40	37
1482
41	52
1483
50	11
1484
53	4
1485
58	23
1486
65	10
1487
68	12
1488
select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr;
1489
companynr	count(distinct concat(fld1,repeat(65,200)))
1490
00	82
1491
29	95
1492
34	70
1493
36	215
1494
37	588
1495
40	37
1496
41	52
1497
50	11
1498
53	4
1499
58	23
1500
65	10
1501
68	12
1502
select companynr,count(distinct floor(fld1/100)) from t2 group by companynr;
1503
companynr	count(distinct floor(fld1/100))
1504
00	47
1505
29	35
1506
34	14
1507
36	69
1508
37	108
1509
40	16
1510
41	11
1511
50	9
1512
53	1
1513
58	1
1514
65	1
1515
68	1
1516
select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr;
1517
companynr	count(distinct concat(repeat(65,1000),floor(fld1/100)))
1518
00	47
1519
29	35
1520
34	14
1521
36	69
1522
37	108
1523
40	16
1524
41	11
1525
50	9
1526
53	1
1527
58	1
1528
65	1
1529
68	1
1530
select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10;
1531
sum(fld1)	fld3
1532
11402	Romans
1533
select name,count(*) from t3 where name='cloakroom' group by name;
1534
name	count(*)
1535
cloakroom	4181
1536
select name,count(*) from t3 where name='cloakroom' and price>10 group by name;
1537
name	count(*)
1538
cloakroom	4181
1539
select count(*) from t3 where name='cloakroom' and price2=823742;
1540
count(*)
1541
4181
1542
select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name;
1543
name	count(*)
1544
cloakroom	4181
1545
select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name;
1546
name	count(*)
1547
extramarital	4181
1548
gazer	4181
1549
gems	4181
1550
Iranizes	4181
1551
spates	4181
1552
tucked	4181
1553
violinist	4181
1554
select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1555
fld3	count(*)
1556
spates	4181
1557
select companynr|0,companyname from t4 group by 1;
1558
companynr|0	companyname
1559
0	Unknown
1560
29	company 1
1561
34	company 2
1562
36	company 3
1563
37	company 4
1564
40	company 5
1565
41	company 6
1566
50	company 11
1567
53	company 7
1568
58	company 8
1569
65	company 9
1570
68	company 10
1571
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname;
1572
companynr	companyname	count(*)
1573
29	company 1	95
1574
68	company 10	12
1575
50	company 11	11
1576
34	company 2	70
1577
36	company 3	215
1578
37	company 4	588
1579
40	company 5	37
1580
41	company 6	52
1581
53	company 7	4
1582
58	company 8	23
1583
65	company 9	10
1584
00	Unknown	82
1585
select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1586
fld1	count(*)
1587
158402	4181
1588
select sum(Period)/count(*) from t1;
1589
sum(Period)/count(*)
1590
9410.0000
1591
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;
1592
companynr	count	sum	diff	func
1593
37	12543	309394878010	0.0000	464091
1594
78	8362	414611089292	0.0000	652236
1595
101	4181	3489454238	0.0000	422281
1596
154	4181	4112197254950	0.0000	643874
1597
311	4181	979599938	0.0000	1300291
1598
447	4181	9929180954	0.0000	1868907
1599
512	4181	3288532102	0.0000	2140672
1600
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
1601
companynr	avg
1602
154	983543950.0000
1603
select companynr,count(*) from t2 group by companynr order by 2 desc;
1604
companynr	count(*)
1605
37	588
1606
36	215
1607
29	95
1608
00	82
1609
34	70
1610
41	52
1611
40	37
1612
58	23
1613
68	12
1614
50	11
1615
65	10
1616
53	4
1617
select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc;
1618
companynr	count(*)
1619
41	52
1620
58	23
1621
68	12
1622
50	11
1623
65	10
1624
53	4
1625
select t2.fld4,t2.fld1,count(price),sum(price),min(price),max(price),avg(price) from t3,t2 where t3.companynr = 37 and t2.fld1 = t3.t2nr group by fld1,t2.fld4;
1626
fld4	fld1	count(price)	sum(price)	min(price)	max(price)	avg(price)
1627
teethe	000001	1	5987435	5987435	5987435	5987435.0000
1628
dreaded	011401	1	5987435	5987435	5987435	5987435.0000
1629
scholastics	011402	1	28357832	28357832	28357832	28357832.0000
1630
audiology	011403	1	39654943	39654943	39654943	39654943.0000
1631
wallet	011501	1	5987435	5987435	5987435	5987435.0000
1632
parters	011701	1	5987435	5987435	5987435	5987435.0000
1633
eschew	011702	1	28357832	28357832	28357832	28357832.0000
1634
quitter	011703	1	39654943	39654943	39654943	39654943.0000
1635
neat	012001	1	5987435	5987435	5987435	5987435.0000
1636
Steinberg	012003	1	39654943	39654943	39654943	39654943.0000
1637
balled	012301	1	5987435	5987435	5987435	5987435.0000
1638
persist	012302	1	28357832	28357832	28357832	28357832.0000
1639
attainments	012303	1	39654943	39654943	39654943	39654943.0000
1640
capably	012501	1	5987435	5987435	5987435	5987435.0000
1641
impulsive	012602	1	28357832	28357832	28357832	28357832.0000
1642
starlet	012603	1	39654943	39654943	39654943	39654943.0000
1643
featherweight	012701	1	5987435	5987435	5987435	5987435.0000
1644
pessimist	012702	1	28357832	28357832	28357832	28357832.0000
1645
daughter	012703	1	39654943	39654943	39654943	39654943.0000
1646
lawgiver	013601	1	5987435	5987435	5987435	5987435.0000
1647
stated	013602	1	28357832	28357832	28357832	28357832.0000
1648
readable	013603	1	39654943	39654943	39654943	39654943.0000
1649
testicle	013801	1	5987435	5987435	5987435	5987435.0000
1650
Parsifal	013802	1	28357832	28357832	28357832	28357832.0000
1651
leavings	013803	1	39654943	39654943	39654943	39654943.0000
1652
squeaking	013901	1	5987435	5987435	5987435	5987435.0000
1653
contrasted	016001	1	5987435	5987435	5987435	5987435.0000
1654
leftover	016201	1	5987435	5987435	5987435	5987435.0000
1655
whiteners	016202	1	28357832	28357832	28357832	28357832.0000
1656
erases	016301	1	5987435	5987435	5987435	5987435.0000
1657
Punjab	016302	1	28357832	28357832	28357832	28357832.0000
1658
Merritt	016303	1	39654943	39654943	39654943	39654943.0000
1659
sweetish	018001	1	5987435	5987435	5987435	5987435.0000
1660
dogging	018002	1	28357832	28357832	28357832	28357832.0000
1661
scornfully	018003	1	39654943	39654943	39654943	39654943.0000
1662
fetters	018012	1	28357832	28357832	28357832	28357832.0000
1663
bivalves	018013	1	39654943	39654943	39654943	39654943.0000
1664
skulking	018021	1	5987435	5987435	5987435	5987435.0000
1665
flint	018022	1	28357832	28357832	28357832	28357832.0000
1666
flopping	018023	1	39654943	39654943	39654943	39654943.0000
1667
Judas	018032	1	28357832	28357832	28357832	28357832.0000
1668
vacuuming	018033	1	39654943	39654943	39654943	39654943.0000
1669
medical	018041	1	5987435	5987435	5987435	5987435.0000
1670
bloodbath	018042	1	28357832	28357832	28357832	28357832.0000
1671
subschema	018043	1	39654943	39654943	39654943	39654943.0000
1672
interdependent	018051	1	5987435	5987435	5987435	5987435.0000
1673
Graves	018052	1	28357832	28357832	28357832	28357832.0000
1674
neonatal	018053	1	39654943	39654943	39654943	39654943.0000
1675
sorters	018061	1	5987435	5987435	5987435	5987435.0000
1676
epistle	018062	1	28357832	28357832	28357832	28357832.0000
1677
Conley	018101	1	5987435	5987435	5987435	5987435.0000
1678
lectured	018102	1	28357832	28357832	28357832	28357832.0000
1679
Abraham	018103	1	39654943	39654943	39654943	39654943.0000
1680
cage	018201	1	5987435	5987435	5987435	5987435.0000
1681
hushes	018202	1	28357832	28357832	28357832	28357832.0000
1682
Simla	018402	1	28357832	28357832	28357832	28357832.0000
1683
reporters	018403	1	39654943	39654943	39654943	39654943.0000
1684
coexist	018601	1	5987435	5987435	5987435	5987435.0000
1685
Beebe	018602	1	28357832	28357832	28357832	28357832.0000
1686
Taoism	018603	1	39654943	39654943	39654943	39654943.0000
1687
Connally	018801	1	5987435	5987435	5987435	5987435.0000
1688
fetched	018802	1	28357832	28357832	28357832	28357832.0000
1689
checkpoints	018803	1	39654943	39654943	39654943	39654943.0000
1690
gritty	018811	1	5987435	5987435	5987435	5987435.0000
1691
firearm	018812	1	28357832	28357832	28357832	28357832.0000
1692
minima	019101	1	5987435	5987435	5987435	5987435.0000
1693
Selfridge	019102	1	28357832	28357832	28357832	28357832.0000
1694
disable	019103	1	39654943	39654943	39654943	39654943.0000
1695
witchcraft	019201	1	5987435	5987435	5987435	5987435.0000
1696
betroth	030501	1	5987435	5987435	5987435	5987435.0000
1697
Manhattanize	030502	1	28357832	28357832	28357832	28357832.0000
1698
imprint	030503	1	39654943	39654943	39654943	39654943.0000
1699
swelling	031901	1	5987435	5987435	5987435	5987435.0000
1700
interrelationships	036001	1	5987435	5987435	5987435	5987435.0000
1701
riser	036002	1	28357832	28357832	28357832	28357832.0000
1702
bee	038001	1	5987435	5987435	5987435	5987435.0000
1703
kanji	038002	1	28357832	28357832	28357832	28357832.0000
1704
dental	038003	1	39654943	39654943	39654943	39654943.0000
1705
railway	038011	1	5987435	5987435	5987435	5987435.0000
1706
validate	038012	1	28357832	28357832	28357832	28357832.0000
1707
normalizes	038013	1	39654943	39654943	39654943	39654943.0000
1708
Kline	038101	1	5987435	5987435	5987435	5987435.0000
1709
Anatole	038102	1	28357832	28357832	28357832	28357832.0000
1710
partridges	038103	1	39654943	39654943	39654943	39654943.0000
1711
recruited	038201	1	5987435	5987435	5987435	5987435.0000
1712
dimensions	038202	1	28357832	28357832	28357832	28357832.0000
1713
Chicana	038203	1	39654943	39654943	39654943	39654943.0000
1714
select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3;
1715
companynr	fld3	sum(price)
1716
512	boat	786542
1717
512	capably	786542
1718
512	cupboard	786542
1719
512	decliner	786542
1720
512	descendants	786542
1721
512	dopers	786542
1722
512	erases	786542
1723
512	Micronesia	786542
1724
512	Miles	786542
1725
512	skies	786542
1726
select t2.companynr,count(*),min(fld3),max(fld3),sum(price),avg(price) from t2,t3 where t3.companynr >= 30 and t3.companynr <= 58 and t3.t2nr = t2.fld1 and 1+1=2 group by t2.companynr;
1727
companynr	count(*)	min(fld3)	max(fld3)	sum(price)	avg(price)
1728
00	1	Omaha	Omaha	5987435	5987435.0000
1729
36	1	dubbed	dubbed	28357832	28357832.0000
1730
37	83	Abraham	Wotan	1908978016	22999735.1325
1731
50	2	scribbled	tapestry	68012775	34006387.5000
1732
select t3.companynr+0,t3.t2nr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 37 group by 1,t3.t2nr,fld3,fld3,fld3,fld3,fld3 order by fld1;
1733
t3.companynr+0	t2nr	fld3	sum(price)
1734
37	1	Omaha	5987435
1735
37	11401	breaking	5987435
1736
37	11402	Romans	28357832
1737
37	11403	intercepted	39654943
1738
37	11501	bewilderingly	5987435
1739
37	11701	astound	5987435
1740
37	11702	admonishing	28357832
1741
37	11703	sumac	39654943
1742
37	12001	flanking	5987435
1743
37	12003	combed	39654943
1744
37	12301	Eulerian	5987435
1745
37	12302	dubbed	28357832
1746
37	12303	Kane	39654943
1747
37	12501	annihilates	5987435
1748
37	12602	Wotan	28357832
1749
37	12603	snatching	39654943
1750
37	12701	grazing	5987435
1751
37	12702	Baird	28357832
1752
37	12703	celery	39654943
1753
37	13601	handgun	5987435
1754
37	13602	foldout	28357832
1755
37	13603	mystic	39654943
1756
37	13801	intelligibility	5987435
1757
37	13802	Augustine	28357832
1758
37	13803	teethe	39654943
1759
37	13901	scholastics	5987435
1760
37	16001	audiology	5987435
1761
37	16201	wallet	5987435
1762
37	16202	parters	28357832
1763
37	16301	eschew	5987435
1764
37	16302	quitter	28357832
1765
37	16303	neat	39654943
1766
37	18001	jarring	5987435
1767
37	18002	tinily	28357832
1768
37	18003	balled	39654943
1769
37	18012	impulsive	28357832
1770
37	18013	starlet	39654943
1771
37	18021	lawgiver	5987435
1772
37	18022	stated	28357832
1773
37	18023	readable	39654943
1774
37	18032	testicle	28357832
1775
37	18033	Parsifal	39654943
1776
37	18041	Punjab	5987435
1777
37	18042	Merritt	28357832
1778
37	18043	Quixotism	39654943
1779
37	18051	sureties	5987435
1780
37	18052	puddings	28357832
1781
37	18053	tapestry	39654943
1782
37	18061	trimmings	5987435
1783
37	18062	humility	28357832
1784
37	18101	tragedies	5987435
1785
37	18102	skulking	28357832
1786
37	18103	flint	39654943
1787
37	18201	relaxing	5987435
1788
37	18202	offload	28357832
1789
37	18402	suites	28357832
1790
37	18403	lists	39654943
1791
37	18601	vacuuming	5987435
1792
37	18602	dentally	28357832
1793
37	18603	humanness	39654943
1794
37	18801	inch	5987435
1795
37	18802	Weissmuller	28357832
1796
37	18803	irresponsibly	39654943
1797
37	18811	repetitions	5987435
1798
37	18812	Antares	28357832
1799
37	19101	ventilate	5987435
1800
37	19102	pityingly	28357832
1801
37	19103	interdependent	39654943
1802
37	19201	Graves	5987435
1803
37	30501	neonatal	5987435
1804
37	30502	scribbled	28357832
1805
37	30503	chafe	39654943
1806
37	31901	realtor	5987435
1807
37	36001	elite	5987435
1808
37	36002	funereal	28357832
1809
37	38001	Conley	5987435
1810
37	38002	lectured	28357832
1811
37	38003	Abraham	39654943
1812
37	38011	groupings	5987435
1813
37	38012	dissociate	28357832
1814
37	38013	coexist	39654943
1815
37	38101	rusting	5987435
1816
37	38102	galling	28357832
1817
37	38103	obliterates	39654943
1818
37	38201	resumes	5987435
1819
37	38202	analyzable	28357832
1820
37	38203	terminator	39654943
1821
select sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1= t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008;
1822
sum(price)
1823
234298
1824
select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1;
1825
fld1	sum(price)
1826
038008	234298
1827
select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502;
1828
companynr	fld1
1829
34	250501
1830
34	250502
1831
select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502;
1832
companynr	fld1
1833
34	250501
1834
34	250502
1835
select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000;
1836
companynr	count	sum
1837
00	82	10355753
1838
29	95	14473298
1839
34	70	17788966
1840
37	588	83602098
1841
41	52	12816335
1842
select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ;
1843
companynr
1844
00
1845
29
1846
34
1847
37
1848
41
1849
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40;
1850
companynr	companyname	count(*)
1851
68	company 10	12
1852
50	company 11	11
1853
40	company 5	37
1854
41	company 6	52
1855
53	company 7	4
1856
58	company 8	23
1857
65	company 9	10
1858
select count(*) from t2;
1859
count(*)
1860
1199
1861
select count(*) from t2 where fld1 < 098024;
1862
count(*)
1863
387
1864
select min(fld1) from t2 where fld1>= 098024;
1865
min(fld1)
1866
98024
1867
select max(fld1) from t2 where fld1>= 098024;
1868
max(fld1)
1869
1232609
1870
select count(*) from t3 where price2=76234234;
1871
count(*)
1872
4181
1873
select count(*) from t3 where companynr=512 and price2=76234234;
1874
count(*)
1875
4181
1876
select min(fld1),max(fld1),count(*) from t2;
1877
min(fld1)	max(fld1)	count(*)
1878
0	1232609	1199
1879
select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742;
1880
min(t2nr)	max(t2nr)
1881
2115	2115
1882
select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78;
1883
count(*)	min(t2nr)	max(t2nr)
1884
4181	4	41804
1885
select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20;
1886
t2nr	count(*)
1887
9	1
1888
19	1
1889
29	1
1890
39	1
1891
49	1
1892
59	1
1893
69	1
1894
79	1
1895
89	1
1896
99	1
1897
109	1
1898
119	1
1899
129	1
1900
139	1
1901
149	1
1902
159	1
1903
169	1
1904
179	1
1905
189	1
1906
199	1
1907
select max(t2nr) from t3 where price=983543950;
1908
max(t2nr)
1909
41807
1910
select t1.period from t3 = t1 limit 1;
1911
period
1912
1001
1913
select t1.period from t1 as t1 limit 1;
1914
period
1915
9410
1916
select t1.period as "Nuvarande period" from t1 as t1 limit 1;
1917
Nuvarande period
1918
9410
1919
select period as ok_period from t1 limit 1;
1920
ok_period
1921
9410
1922
select period as ok_period from t1 group by ok_period limit 1;
1923
ok_period
1924
9410
1925
select 1+1 as summa from t1 group by summa limit 1;
1926
summa
1927
2
1928
select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;
1929
Nuvarande period
1930
9410
1931
show tables;
1932
Tables_in_test
1933
t1
1934
t2
1935
t3
1936
t4
1937
show tables from test like "s%";
1938
Tables_in_test (s%)
1939
show tables from test like "t?";
1940
Tables_in_test (t?)
1941
show full columns from t2;
1942
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
1943
auto	int(11)	NULL	NO	PRI	NULL	auto_increment	#	
1944
fld1	int(6) unsigned zerofill	NULL	NO	UNI	NULL		#	
1945
companynr	tinyint(2) unsigned zerofill	NULL	NO		NULL		#	
1946
fld3	char(30)	latin1_swedish_ci	NO	MUL	NULL		#	
1947
fld4	char(35)	latin1_swedish_ci	NO		NULL		#	
1948
fld5	char(35)	latin1_swedish_ci	NO		NULL		#	
1949
fld6	char(4)	latin1_swedish_ci	NO		NULL		#	
1950
show full columns from t2 from test like 'f%';
1951
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
1952
fld1	int(6) unsigned zerofill	NULL	NO	UNI	NULL		#	
1953
fld3	char(30)	latin1_swedish_ci	NO	MUL	NULL		#	
1954
fld4	char(35)	latin1_swedish_ci	NO		NULL		#	
1955
fld5	char(35)	latin1_swedish_ci	NO		NULL		#	
1956
fld6	char(4)	latin1_swedish_ci	NO		NULL		#	
1957
show full columns from t2 from test like 's%';
1958
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
1959
drop table t4, t3, t2, t1;
1960
CREATE TABLE t1 (
67 by Brian Aker
First pass for removing mediumint (3 byte INT type).
1961
id bigint(8) unsigned NOT NULL auto_increment,
1 by brian
clean slate
1962
pseudo varchar(35) NOT NULL default '',
1963
PRIMARY KEY  (id),
1964
UNIQUE KEY pseudo (pseudo)
1965
);
1966
INSERT INTO t1 (pseudo) VALUES ('test');
1967
INSERT INTO t1 (pseudo) VALUES ('test1');
1968
SELECT 1 as rnd1 from t1 where rand() > 2;
1969
rnd1
1970
DROP TABLE t1;
1971
CREATE TABLE t1 (gvid int(10) unsigned default NULL,  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  mmid int(10) unsigned default NULL,  hdid int(10) unsigned default NULL,  fsid int(10) unsigned default NULL,  ctid int(10) unsigned default NULL,  dtid int(10) unsigned default NULL,  cost int(10) unsigned default NULL,  performance int(10) unsigned default NULL,  serialnumber bigint(20) unsigned default NULL,  monitored tinyint(3) unsigned default '1',  removed tinyint(3) unsigned default '0',  target tinyint(3) unsigned default '0',  dt_modified timestamp NOT NULL,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
1972
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);
1973
CREATE TABLE t2 (  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  sampletid smallint(5) unsigned default NULL,  sampletime datetime default NULL,  samplevalue bigint(20) unsigned default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
1974
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
1975
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;
1976
gvid	the_success	the_fail	the_size	the_time
1977
Warnings:
1978
Warning	1292	Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1
1979
Warning	1292	Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1
1980
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;
1981
gvid	the_success	the_fail	the_size	the_time
1982
DROP TABLE t1,t2;
1983
create table  t1 (  A_Id bigint(20) NOT NULL default '0',  A_UpdateBy char(10) NOT NULL default '',  A_UpdateDate bigint(20) NOT NULL default '0',  A_UpdateSerial int(11) NOT NULL default '0',  other_types bigint(20) NOT NULL default '0',  wss_type bigint(20) NOT NULL default '0');
1984
INSERT INTO t1 VALUES (102935998719055004,'brade',1029359987,2,102935229116544068,102935229216544093);
1985
select wss_type from t1 where wss_type ='102935229216544106';
1986
wss_type
1987
select wss_type from t1 where wss_type ='102935229216544105';
1988
wss_type
1989
select wss_type from t1 where wss_type ='102935229216544104';
1990
wss_type
1991
select wss_type from t1 where wss_type ='102935229216544093';
1992
wss_type
1993
102935229216544093
1994
select wss_type from t1 where wss_type =102935229216544093;
1995
wss_type
1996
102935229216544093
1997
drop table t1;
1998
select 1+2,"aaaa",3.13*2.0 into @a,@b,@c;
1999
select @a;
2000
@a
2001
3
2002
select @b;
2003
@b
2004
aaaa
2005
select @c;
2006
@c
2007
6.260
2008
create table t1 (a int not null auto_increment primary key);
2009
insert into t1 values ();
2010
insert into t1 values ();
2011
insert into t1 values ();
2012
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
2013
a	a
2014
1	1
2015
2	1
2016
3	1
2017
1	2
2018
2	2
2019
3	2
2020
1	3
2021
2	3
2022
3	3
2023
select * from t1, (t1 as t2 left join t1 as t3 using (a));
2024
a	a
2025
1	1
2026
2	1
2027
3	1
2028
1	2
2029
2	2
2030
3	2
2031
1	3
2032
2	3
2033
3	3
2034
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
2035
a	a
2036
1	1
2037
2	1
2038
3	1
2039
1	2
2040
2	2
2041
3	2
2042
1	3
2043
2	3
2044
3	3
2045
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
2046
a	a
2047
1	1
2048
2	1
2049
3	1
2050
1	2
2051
2	2
2052
3	2
2053
1	3
2054
2	3
2055
3	3
2056
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
2057
a	a
2058
1	2
201 by Brian Aker
Convert default engine to Innodb
2059
1	3
1 by brian
clean slate
2060
2	2
201 by Brian Aker
Convert default engine to Innodb
2061
2	3
1 by brian
clean slate
2062
3	2
2063
3	3
2064
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
2065
a	a
2066
2	1
2067
3	1
2068
2	2
2069
3	2
2070
2	3
2071
3	3
2072
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
2073
a
2074
1
2075
2
2076
3
2077
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
2078
a
2079
1
2080
2
2081
3
2082
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
2083
a	a
2084
1	2
2085
1	3
2086
2	2
2087
2	3
2088
3	2
2089
3	3
2090
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
2091
a	a
2092
1	NULL
2093
2	1
2094
2	2
2095
2	3
2096
3	1
2097
3	2
2098
3	3
2099
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
2100
a
2101
1
2102
2
2103
3
2104
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
2105
a
2106
1
2107
2
2108
3
2109
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
2110
a
2111
1
2112
2
2113
3
2114
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
2115
a
2116
1
2117
2
2118
3
2119
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
2120
a	a
2121
NULL	1
2122
1	2
2123
2	2
2124
3	2
2125
1	3
2126
2	3
2127
3	3
2128
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
2129
a	a
2130
2	1
2131
3	1
2132
2	2
2133
3	2
2134
2	3
2135
3	3
2136
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
2137
a
2138
1
2139
2
2140
3
2141
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
2142
a
2143
1
2144
2
2145
3
2146
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
2147
a
2148
1
2149
2
2150
3
2151
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
2152
a
2153
1
2154
2
2155
3
2156
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
2157
a
2158
1
2159
2
2160
3
2161
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
2162
a
2163
1
2164
2
2165
3
2166
drop table t1;
2167
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;
2168
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);
2169
CREATE TABLE t2 ( id int(11) NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
2170
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
2171
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
2172
aa	id	t2_id	id
2173
2	8299	2517	2517
2174
3	8301	2518	2518
2175
4	8302	2519	2519
2176
5	8303	2520	2520
2177
6	8304	2521	2521
2178
drop table t1,t2;
2179
create table t1 (id1 int NOT NULL);
2180
create table t2 (id2 int NOT NULL);
2181
create table t3 (id3 int NOT NULL);
2182
create table t4 (id4 int NOT NULL, id44 int NOT NULL, KEY (id4));
2183
insert into t1 values (1);
2184
insert into t1 values (2);
2185
insert into t2 values (1);
2186
insert into t4 values (1,1);
2187
select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
2188
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
2189
id1	id2	id3	id4	id44
2190
1	1	NULL	NULL	NULL
2191
drop table t1,t2,t3,t4;
2192
create table t1(s varchar(10) not null);
2193
create table t2(s varchar(10) not null primary key);
2194
create table t3(s varchar(10) not null primary key);
2195
insert into t1 values ('one\t'), ('two\t');
2196
insert into t2 values ('one\r'), ('two\t');
2197
insert into t3 values ('one '), ('two\t');
2198
select * from t1 where s = 'one';
2199
s
2200
select * from t2 where s = 'one';
2201
s
2202
select * from t3 where s = 'one';
2203
s
2204
one 
2205
select * from t1,t2 where t1.s = t2.s;
2206
s	s
2207
two		two	
2208
select * from t2,t3 where t2.s = t3.s;
2209
s	s
2210
two		two	
2211
drop table t1, t2, t3;
2212
create table t1 (a integer,  b integer, index(a), index(b));
2213
create table t2 (c integer,  d integer, index(c), index(d));
2214
insert into t1 values (1,2), (2,2), (3,2), (4,2);
2215
insert into t2 values (1,3), (2,3), (3,4), (4,4);
2216
select * from t1 left join t2 on a=c where d in (4);
2217
a	b	c	d
2218
3	2	3	4
2219
4	2	4	4
2220
select * from t1 left join t2 on a=c where d = 4;
2221
a	b	c	d
2222
3	2	3	4
2223
4	2	4	4
2224
drop table t1, t2;
2225
CREATE TABLE t1 (
2226
i int(11) NOT NULL default '0',
2227
c char(10) NOT NULL default '',
2228
PRIMARY KEY  (i),
2229
UNIQUE KEY c (c)
2230
) ENGINE=MyISAM;
2231
INSERT INTO t1 VALUES (1,'a');
2232
INSERT INTO t1 VALUES (2,'b');
2233
INSERT INTO t1 VALUES (3,'c');
2234
EXPLAIN SELECT i FROM t1 WHERE i=1;
2235
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2236
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
2237
DROP TABLE t1;
2238
CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );
2239
CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
2240
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
2241
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
2242
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
2243
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2244
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
201 by Brian Aker
Convert default engine to Innodb
2245
1	SIMPLE	t2	ref	a	a	23	test.t1.a	1	
1 by brian
clean slate
2246
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
2247
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2248
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
201 by Brian Aker
Convert default engine to Innodb
2249
1	SIMPLE	t2	ref	a	a	23	test.t1.a	1	
1 by brian
clean slate
2250
DROP TABLE t1, t2;
2251
CREATE TABLE t1 ( city char(30) );
2252
INSERT INTO t1 VALUES ('London');
2253
INSERT INTO t1 VALUES ('Paris');
2254
SELECT * FROM t1 WHERE city='London';
2255
city
2256
London
2257
SELECT * FROM t1 WHERE city='london';
2258
city
2259
London
2260
EXPLAIN SELECT * FROM t1 WHERE city='London' AND city='london';
2261
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2262
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
2263
SELECT * FROM t1 WHERE city='London' AND city='london';
2264
city
2265
London
2266
EXPLAIN SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
2267
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2268
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
2269
SELECT * FROM t1 WHERE city LIKE '%london%' AND city='London';
2270
city
2271
London
2272
DROP TABLE t1;
2273
create table t1 (a int(11) unsigned, b int(11) unsigned);
2274
insert into t1 values (1,0), (1,1), (1,2);
2275
select a-b  from t1 order by 1;
2276
a-b  
2277
0
2278
1
2279
18446744073709551615
2280
select a-b , (a-b < 0)  from t1 order by 1;
2281
a-b 	(a-b < 0)
2282
0	0
2283
1	0
2284
18446744073709551615	0
2285
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
2286
d	(a-b >= 0)	b
2287
1	1	0
2288
0	1	1
2289
18446744073709551615	1	2
2290
select cast((a - b) as unsigned) from t1 order by 1;
2291
cast((a - b) as unsigned)
2292
0
2293
1
2294
18446744073709551615
2295
drop table t1;
2296
create table t1 (a int(11));
2297
select all all * from t1;
2298
a
2299
select distinct distinct * from t1;
2300
a
2301
select all distinct * from t1;
2302
ERROR HY000: Incorrect usage of ALL and DISTINCT
2303
select distinct all * from t1;
2304
ERROR HY000: Incorrect usage of ALL and DISTINCT
2305
drop table t1;
2306
CREATE TABLE t1 (
2307
kunde_intern_id int(10) unsigned NOT NULL default '0',
2308
kunde_id int(10) unsigned NOT NULL default '0',
2309
FK_firma_id int(10) unsigned NOT NULL default '0',
2310
aktuell enum('Ja','Nein') NOT NULL default 'Ja',
2311
vorname varchar(128) NOT NULL default '',
2312
nachname varchar(128) NOT NULL default '',
2313
geloescht enum('Ja','Nein') NOT NULL default 'Nein',
2314
firma varchar(128) NOT NULL default ''
2315
);
2316
INSERT INTO t1 VALUES 
2317
(3964,3051,1,'Ja','Vorname1','1Nachname','Nein','Print Schau XXXX'),
2318
(3965,3051111,1,'Ja','Vorname1111','1111Nachname','Nein','Print Schau XXXX');
2319
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname, geloescht FROM t1
2320
WHERE
2321
(
2322
(
2323
( '' != '' AND firma LIKE CONCAT('%', '', '%'))
2324
OR
2325
(vorname LIKE CONCAT('%', 'Vorname1', '%') AND 
2326
nachname LIKE CONCAT('%', '1Nachname', '%') AND 
2327
'Vorname1' != '' AND 'xxxx' != '')
2328
)
2329
AND
2330
(
2331
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
2332
)
2333
)
2334
;
2335
kunde_id	FK_firma_id	aktuell	vorname	nachname	geloescht
2336
SELECT kunde_id ,FK_firma_id ,aktuell, vorname, nachname,
2337
geloescht FROM t1
2338
WHERE
2339
(
2340
(
2341
aktuell = 'Ja' AND geloescht = 'Nein' AND FK_firma_id = 2
2342
)
2343
AND
2344
(
2345
( '' != '' AND firma LIKE CONCAT('%', '', '%')  )
2346
OR
2347
(  vorname LIKE CONCAT('%', 'Vorname1', '%') AND
2348
nachname LIKE CONCAT('%', '1Nachname', '%') AND 'Vorname1' != '' AND
2349
'xxxx' != '')
2350
)
2351
)
2352
;
2353
kunde_id	FK_firma_id	aktuell	vorname	nachname	geloescht
2354
SELECT COUNT(*) FROM t1 WHERE 
2355
( 0 OR (vorname LIKE '%Vorname1%' AND nachname LIKE '%1Nachname%' AND 1)) 
2356
AND FK_firma_id = 2;
2357
COUNT(*)
2358
0
2359
drop table t1;
2360
CREATE TABLE t1 (b BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (b));
2361
INSERT INTO t1 VALUES (0x8000000000000000);
2362
SELECT b FROM t1 WHERE b=0x8000000000000000;
2363
b
2364
9223372036854775808
2365
DROP TABLE t1;
2366
CREATE TABLE `t1` ( `gid` int(11) default NULL, `uid` int(11) default NULL);
2367
CREATE TABLE `t2` ( `ident` int(11) default NULL, `level` char(16) default NULL);
2368
INSERT INTO `t2` VALUES (0,'READ');
2369
CREATE TABLE `t3` ( `id` int(11) default NULL, `name` char(16) default NULL);
2370
INSERT INTO `t3` VALUES (1,'fs');
2371
select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0);
2372
id	name	gid	uid	ident	level
2373
1	fs	NULL	NULL	0	READ
2374
drop table t1,t2,t3;
2375
CREATE TABLE t1 (
2376
acct_id int(11) NOT NULL default '0',
2377
profile_id smallint(6) default NULL,
2378
UNIQUE KEY t1$acct_id (acct_id),
2379
KEY t1$profile_id (profile_id)
2380
);
2381
INSERT INTO t1 VALUES (132,17),(133,18);
2382
CREATE TABLE t2 (
2383
profile_id smallint(6) default NULL,
2384
queue_id int(11) default NULL,
2385
seq int(11) default NULL,
2386
KEY t2$queue_id (queue_id)
2387
);
2388
INSERT INTO t2 VALUES (17,31,4),(17,30,3),(17,36,2),(17,37,1);
2389
CREATE TABLE t3 (
2390
id int(11) NOT NULL default '0',
2391
qtype int(11) default NULL,
2392
seq int(11) default NULL,
2393
warn_lvl int(11) default NULL,
2394
crit_lvl int(11) default NULL,
2395
rr1 tinyint(4) NOT NULL default '0',
2396
rr2 int(11) default NULL,
2397
default_queue tinyint(4) NOT NULL default '0',
2398
KEY t3$qtype (qtype),
2399
KEY t3$id (id)
2400
);
2401
INSERT INTO t3 VALUES (30,1,29,NULL,NULL,0,NULL,0),(31,1,28,NULL,NULL,0,NULL,0),
2402
(36,1,34,NULL,NULL,0,NULL,0),(37,1,35,NULL,NULL,0,121,0);
2403
SELECT COUNT(*) FROM t1 a STRAIGHT_JOIN t2 pq STRAIGHT_JOIN t3 q 
2404
WHERE 
2405
(pq.profile_id = a.profile_id) AND (a.acct_id = 132) AND 
2406
(pq.queue_id = q.id) AND (q.rr1 <> 1);
2407
COUNT(*)
2408
4
2409
drop table t1,t2,t3;
2410
create table t1 (f1 int);
2411
insert into t1 values (1),(NULL);
2412
create table t2 (f2 int, f3 int, f4 int);
2413
create index idx1 on t2 (f4);
2414
insert into t2 values (1,2,3),(2,4,6);
2415
select A.f2 from t1 left join t2 A on A.f2 = f1 where A.f3=(select min(f3)
2416
from  t2 C where A.f4 = C.f4) or A.f3 IS NULL;
2417
f2
2418
1
2419
NULL
2420
drop table t1,t2;
2421
create table t2 (a tinyint unsigned);
2422
create index t2i on t2(a);
2423
insert into t2 values (0), (254), (255);
2424
select * from t2 where a > -1;
2425
a
2426
0
2427
254
2428
255
2429
drop table t2;
2430
CREATE TABLE t1 (a INT, b INT);
2431
(SELECT a, b AS c FROM t1) ORDER BY c+1;
2432
a	c
2433
(SELECT a, b AS c FROM t1) ORDER BY b+1;
2434
a	c
2435
SELECT a, b AS c FROM t1 ORDER BY c+1;
2436
a	c
2437
SELECT a, b AS c FROM t1 ORDER BY b+1;
2438
a	c
2439
drop table t1;
2440
create table t1(f1 int, f2 int);
2441
create table t2(f3 int);
2442
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,1));
2443
f1
2444
select f1 from t1,t2 where f1=f2 and (f1,NULL) = ((1,1));
2445
f1
2446
select f1 from t1,t2 where f1=f2 and (f1,f2) = ((1,NULL));
2447
f1
2448
insert into t1 values(1,1),(2,null);
2449
insert into t2 values(2);
2450
select * from t1,t2 where f1=f3 and (f1,f2) = (2,null);
2451
f1	f2	f3
2452
select * from t1,t2 where f1=f3 and (f1,f2) <=> (2,null);
2453
f1	f2	f3
2454
2	NULL	2
2455
drop table t1,t2;
2456
create table t1 (f1 int not null auto_increment primary key, f2 varchar(10));
2457
create table t11 like t1;
2458
insert into t1 values(1,""),(2,"");
2459
show table status like 't1%';
2460
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
201 by Brian Aker
Convert default engine to Innodb
2461
t1	InnoDB	10	Compact	2	8192	X	X	X	X	X	X	X	X	latin1_swedish_ci	NULL		
2462
t11	InnoDB	10	Compact	0	0	X	X	X	X	X	X	X	X	latin1_swedish_ci	NULL		
1 by brian
clean slate
2463
select 123 as a from t1 where f1 is null;
2464
a
2465
drop table t1,t11;
2466
CREATE TABLE t1 ( a INT NOT NULL, b INT NOT NULL, UNIQUE idx (a,b) );
2467
INSERT INTO t1 VALUES (1,1),(1,2),(1,3),(1,4);
2468
CREATE TABLE t2 ( a INT NOT NULL, b INT NOT NULL, e INT );
2469
INSERT INTO t2 VALUES ( 1,10,1), (1,10,2), (1,11,1), (1,11,2), (1,2,1), (1,2,2),(1,2,3);
2470
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
2471
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c;
2472
a	b	c	d
2473
1	2	1	1
2474
1	2	2	1
2475
1	2	3	1
2476
1	10		2
2477
1	11		2
2478
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
2479
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t1.a, t1.b, c;
2480
a	b	c	d
2481
1	10		4
2482
1	2	1	1
2483
1	2	2	1
2484
1	2	3	1
2485
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2 LEFT JOIN
2486
t1 ON t2.a = t1.a AND t2.b = t1.b GROUP BY t2.a, t2.b, c;
2487
a	b	c	d
2488
1	2	1	1
2489
1	2	2	1
2490
1	2	3	1
2491
1	10		2
2492
1	11		2
2493
SELECT t2.a, t2.b, IF(t1.b IS NULL,'',e) AS c, COUNT(*) AS d FROM t2,t1
2494
WHERE t2.a = t1.a AND t2.b = t1.b GROUP BY a, b, c;
2495
a	b	c	d
2496
1	2	1	1
2497
1	2	2	1
2498
1	2	3	1
2499
DROP TABLE IF EXISTS t1, t2;
2500
create table t1 (f1 int primary key, f2 int);
2501
create table t2 (f3 int, f4 int, primary key(f3,f4));
2502
insert into t1 values (1,1);
2503
insert into t2 values (1,1),(1,2);
2504
select distinct count(f2) >0 from t1 left join t2 on f1=f3 group by f1;
2505
count(f2) >0
2506
1
2507
drop table t1,t2;
2508
create table t1 (f1 int,f2 int);
2509
insert into t1 values(1,1);
2510
create table t2 (f3 int, f4 int, primary key(f3,f4));
2511
insert into t2 values(1,1);
2512
select * from t1 where f1 in (select f3 from t2 where (f3,f4)= (select f3,f4 from t2));
2513
f1	f2
2514
1	1
2515
drop table t1,t2;
2516
CREATE TABLE t1(a int, b int, c int, KEY b(b), KEY c(c));
2517
insert into t1 values (1,0,0),(2,0,0);
2518
CREATE TABLE t2 (a int, b varchar(2), c varchar(2), PRIMARY KEY(a));
2519
insert into t2 values (1,'',''), (2,'','');
2520
CREATE TABLE t3 (a int, b int, PRIMARY KEY (a,b), KEY a (a), KEY b (b));
2521
insert into t3 values (1,1),(1,2);
2522
DROP TABLE t1,t2,t3;
2523
CREATE TABLE t1 (a int, INDEX idx(a));
2524
INSERT INTO t1 VALUES (2), (3), (1);
2525
EXPLAIN SELECT * FROM t1 IGNORE INDEX (idx);
2526
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2527
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
2528
EXPLAIN SELECT * FROM t1 IGNORE INDEX (a);
2529
ERROR 42000: Key 'a' doesn't exist in table 't1'
2530
EXPLAIN SELECT * FROM t1 FORCE INDEX (a);
2531
ERROR 42000: Key 'a' doesn't exist in table 't1'
2532
DROP TABLE t1;
2533
CREATE TABLE t1 (a int, b int);
2534
INSERT INTO t1 VALUES (1,1), (2,1), (4,10);
2535
CREATE TABLE t2 (a int PRIMARY KEY, b int, KEY b (b));
2536
INSERT INTO t2 VALUES (1,NULL), (2,10);
2537
ALTER TABLE t1 ENABLE KEYS;
201 by Brian Aker
Convert default engine to Innodb
2538
Warnings:
2539
Note	1031	Table storage engine for 't1' doesn't have this option
1 by brian
clean slate
2540
EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
2541
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
2542
1	SIMPLE	t2	index	b	PRIMARY	4	NULL	2	
1 by brian
clean slate
2543
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer
2544
SELECT STRAIGHT_JOIN * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
2545
a	b	a	b
2546
1	NULL	1	1
2547
1	NULL	2	1
2548
1	NULL	4	10
2549
2	10	4	10
2550
EXPLAIN SELECT STRAIGHT_JOIN COUNT(*) FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
2551
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
2552
1	SIMPLE	t2	index	b	PRIMARY	4	NULL	2	
1 by brian
clean slate
2553
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer
2554
SELECT STRAIGHT_JOIN * FROM t2, t1 WHERE t1.b = t2.b OR t2.b IS NULL;
2555
a	b	a	b
2556
1	NULL	1	1
2557
1	NULL	2	1
2558
1	NULL	4	10
2559
2	10	4	10
2560
DROP TABLE IF EXISTS t1,t2;
2561
CREATE TABLE t1 (key1 float default NULL, UNIQUE KEY key1 (key1));
2562
CREATE TABLE t2 (key2 float default NULL, UNIQUE KEY key2 (key2));
2563
INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941);
2564
INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941);
2565
select max(key1) from t1 where key1 <= 0.6158;
2566
max(key1)
166 by Brian Aker
Removal of FLOAT type
2567
0.6158
1 by brian
clean slate
2568
select max(key2) from t2 where key2 <= 1.6158;
2569
max(key2)
166 by Brian Aker
Removal of FLOAT type
2570
1.6158
1 by brian
clean slate
2571
select min(key1) from t1 where key1 >= 0.3762;
2572
min(key1)
166 by Brian Aker
Removal of FLOAT type
2573
0.3762
1 by brian
clean slate
2574
select min(key2) from t2 where key2 >= 1.3762;
2575
min(key2)
166 by Brian Aker
Removal of FLOAT type
2576
1.3762
1 by brian
clean slate
2577
select max(key1), min(key2) from t1, t2
2578
where key1 <= 0.6158 and key2 >= 1.3762;
2579
max(key1)	min(key2)
166 by Brian Aker
Removal of FLOAT type
2580
0.6158	1.3762
1 by brian
clean slate
2581
select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
2582
max(key1)
166 by Brian Aker
Removal of FLOAT type
2583
0.6158
1 by brian
clean slate
2584
select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
2585
min(key1)
166 by Brian Aker
Removal of FLOAT type
2586
0.3762
1 by brian
clean slate
2587
DROP TABLE t1,t2;
2588
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
2589
INSERT INTO t1 VALUES (10);
2590
SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
2591
i='1e+01'	i=1e+01	i in (1e+01,1e+01)	i in ('1e+01','1e+01')
2592
1	1	1	1
2593
DROP TABLE t1;
2594
CREATE TABLE t1 (c0 int);
2595
CREATE TABLE t2 (c0 int);
2596
INSERT INTO t1 VALUES(@@connect_timeout);
2597
INSERT INTO t2 VALUES(@@connect_timeout);
2598
SELECT * FROM t1 JOIN t2 ON t1.c0 = t2.c0 WHERE (t1.c0 <=> @@connect_timeout);
2599
c0	c0
2600
X	X
2601
DROP TABLE t1, t2;
2602
End of 4.1 tests
2603
CREATE TABLE t1 ( 
2604
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', 
2605
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', 
2606
F2I4 int(11) NOT NULL default '0' 
2607
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2608
INSERT INTO t1 VALUES 
2609
('W%RT', '0100',  1), 
2610
('W-RT', '0100', 1), 
2611
('WART', '0100', 1), 
2612
('WART', '0200', 1), 
2613
('WERT', '0100', 2), 
2614
('WORT','0200', 2), 
2615
('WT', '0100', 2), 
2616
('W_RT', '0100', 2), 
2617
('WaRT', '0100', 3), 
2618
('WART', '0300', 3), 
2619
('WRT' , '0400', 3), 
2620
('WURM', '0500', 3), 
2621
('W%T', '0600', 4), 
2622
('WA%T', '0700', 4), 
2623
('WA_T', '0800', 4);
2624
SELECT K2C4, K4N4, F2I4 FROM t1
2625
WHERE  K2C4 = 'WART' AND 
2626
(F2I4 = 2 AND K2C4 = 'WART' OR (F2I4 = 2 OR K4N4 = '0200'));
2627
K2C4	K4N4	F2I4
2628
WART	0200	1
2629
SELECT K2C4, K4N4, F2I4 FROM t1
2630
WHERE  K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200');
2631
K2C4	K4N4	F2I4
2632
WART	0100	1
2633
WART	0200	1
2634
WART	0300	3
2635
DROP TABLE t1;
2636
create table t1 (a int, b int);
2637
create table t2 like t1;
2638
select t1.a from (t1 inner join t2 on t1.a=t2.a) where t2.a=1;
2639
a
2640
select t1.a from ((t1 inner join t2 on t1.a=t2.a)) where t2.a=1;
2641
a
2642
select x.a, y.a, z.a from ( (t1 x inner join t2 y on x.a=y.a) inner join t2 z on y.a=z.a) WHERE x.a=1;
2643
a	a	a
2644
drop table t1,t2;
2645
create table t1 (s1 varchar(5));
2646
insert into t1 values ('Wall');
2647
select min(s1) from t1 group by s1 with rollup;
2648
min(s1)
2649
Wall
2650
Wall
2651
drop table t1;
2652
create table t1 (s1 int) engine=myisam;
2653
insert into t1 values (0);
2654
select avg(distinct s1) from t1 group by s1 with rollup;
2655
avg(distinct s1)
2656
0.0000
2657
0.0000
2658
drop table t1;
2659
create table t1 (s1 int);
2660
insert into t1 values (null),(1);
2661
select distinct avg(s1) as x from t1 group by s1 with rollup;
2662
x
2663
NULL
2664
1.0000
2665
drop table t1;
2666
CREATE TABLE t1 (a int);
2667
CREATE TABLE t2 (a int);
2668
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
2669
INSERT INTO t2 VALUES (2), (4), (6);
2670
SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a;
2671
a
2672
2
2673
4
2674
EXPLAIN SELECT t1.a FROM t1 STRAIGHT_JOIN t2 ON t1.a=t2.a;
2675
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2676
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
2677
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	Using where; Using join buffer
2678
EXPLAIN SELECT t1.a FROM t1 INNER JOIN t2 ON t1.a=t2.a;
2679
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2680
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	
2681
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using where; Using join buffer
2682
DROP TABLE t1,t2;
2683
select x'10' + 0, X'10' + 0, b'10' + 0, B'10' + 0;
2684
x'10' + 0	X'10' + 0	b'10' + 0	B'10' + 0
2685
16	16	2	2
2686
create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null);
2687
create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4));
2688
insert into t1 values (" 2", 2);
2689
insert into t2 values (" 2", " one "),(" 2", " two ");
2690
select * from t1 left join t2 on f1 = f3;
2691
f1	f2	f3	f4
2692
 2	2	 2	 one 
2693
 2	2	 2	 two 
2694
drop table t1,t2;
2695
create table t1 (pk int primary key, b int);
2696
create table t2 (pk int primary key, c int);
2697
select pk from t1 inner join t2 using (pk);
2698
pk
2699
drop table t1,t2;
2700
create table t1 (a int(10), t1_val int(10));
2701
create table t2 (b int(10), t2_val int(10));
2702
create table t3 (a int(10), b int(10));
2703
insert into t1 values (1,1),(2,2);
2704
insert into t2 values (1,1),(2,2),(3,3);
2705
insert into t3 values (1,1),(2,1),(3,1),(4,1);
2706
select * from t1 natural join t2 natural join t3;
2707
a	b	t1_val	t2_val
2708
1	1	1	1
2709
2	1	2	1
2710
select * from t1 natural join t3 natural join t2;
2711
b	a	t1_val	t2_val
2712
1	1	1	1
2713
1	2	2	1
2714
drop table t1, t2, t3;
2715
create table t1 (a char(1));
2716
create table t2 (a char(1));
2717
insert into t1 values ('a'),('b'),('c');
2718
insert into t2 values ('b'),('c'),('d');
2719
select a from t1 natural join t2;
2720
a
2721
b
2722
c
2723
select * from t1 natural join t2 where a = 'b';
2724
a
2725
b
2726
drop table t1, t2;
2727
CREATE TABLE t1 (`id` TINYINT);
2728
CREATE TABLE t2 (`id` TINYINT);
2729
CREATE TABLE t3 (`id` TINYINT);
2730
INSERT INTO t1 VALUES (1),(2),(3);
2731
INSERT INTO t2 VALUES (2);
2732
INSERT INTO t3 VALUES (3);
2733
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2734
ERROR 23000: Column 'id' in from clause is ambiguous
2735
SELECT t1.id,t3.id FROM t1 JOIN t2 ON (t2.notacolumn=t1.id) LEFT JOIN t3 USING (id);
2736
ERROR 23000: Column 'id' in from clause is ambiguous
2737
SELECT id,t3.id FROM t1 JOIN t2 ON (t2.id=t1.id) LEFT JOIN t3 USING (id);
2738
ERROR 23000: Column 'id' in from clause is ambiguous
2739
SELECT id,t3.id FROM (t1 JOIN t2 ON (t2.id=t1.id)) LEFT JOIN t3 USING (id);
2740
ERROR 23000: Column 'id' in from clause is ambiguous
2741
drop table t1, t2, t3;
2742
create table t1 (a int(10),b int(10));
2743
create table t2 (a int(10),b int(10));
2744
insert into t1 values (1,10),(2,20),(3,30);
2745
insert into t2 values (1,10);
2746
select * from t1 inner join t2 using (A);
2747
a	b	b
2748
1	10	10
2749
select * from t1 inner join t2 using (a);
2750
a	b	b
2751
1	10	10
2752
drop table t1, t2;
2753
create table t1 (a int, c int);
2754
create table t2 (b int);
2755
create table t3 (b int, a int);
2756
create table t4 (c int);
2757
insert into t1 values (1,1);
2758
insert into t2 values (1);
2759
insert into t3 values (1,1);
2760
insert into t4 values (1);
2761
select * from t1 join t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
2762
a	c	b	b	a
2763
1	1	1	1	1
2764
select * from t1, t2 join t3 on (t2.b = t3.b and t1.a = t3.a);
2765
ERROR 42S22: Unknown column 't1.a' in 'on clause'
2766
select * from t1 join t2 join t3 join t4 on (t1.a = t4.c and t2.b = t4.c);
2767
a	c	b	b	a	c
2768
1	1	1	1	1	1
2769
select * from t1 join t2 join t4 using (c);
2770
c	a	b
2771
1	1	1
2772
drop table t1, t2, t3, t4;
2773
create table t1(x int, y int);
2774
create table t2(x int, y int);
2775
create table t3(x int, primary key(x));
2776
insert into t1 values (1, 1), (2, 1), (3, 1), (4, 3), (5, 6), (6, 6);
2777
insert into t2 values (1, 1), (2, 1), (3, 3), (4, 6), (5, 6);
2778
insert into t3 values (1), (2), (3), (4), (5);
2779
select t1.x, t3.x from t1, t2, t3  where t1.x = t2.x and t3.x >= t1.y and t3.x <= t2.y;
2780
x	x
2781
1	1
2782
2	1
2783
3	1
2784
3	2
2785
3	3
2786
4	3
2787
4	4
2788
4	5
2789
drop table t1,t2,t3;
2790
create table t1 (id int(11) not null default '0');
2791
insert into t1 values (123),(191),(192);
2792
create table t2 (id char(16) character set utf8 not null);
2793
insert into t2 values ('58013'),('58014'),('58015'),('58016');
2794
create table t3 (a_id int(11) not null, b_id char(16) character set utf8);
2795
insert into t3 values (123,null),(123,null),(123,null),(123,null),(123,null),(123,'58013');
2796
select count(*)
2797
from t1 inner join (t3 left join t2 on t2.id = t3.b_id) on t1.id = t3.a_id;
2798
count(*)
2799
6
2800
select count(*)
2801
from t1 inner join (t2 right join t3 on t2.id = t3.b_id) on t1.id = t3.a_id;
2802
count(*)
2803
6
2804
drop table t1,t2,t3;
2805
create table t1 (a int);
2806
create table t2 (b int);
2807
create table t3 (c int);
2808
select * from t1 join t2 join t3 on (t1.a=t3.c);
2809
a	b	c
2810
select * from t1 join t2 left join t3 on (t1.a=t3.c);
2811
a	b	c
2812
select * from t1 join t2 right join t3 on (t1.a=t3.c);
2813
a	b	c
2814
select * from t1 join t2 straight_join t3 on (t1.a=t3.c);
2815
a	b	c
2816
drop table t1, t2 ,t3;
2817
create table t1(f1 int, f2 date);
2818
insert into t1 values(1,'2005-01-01'),(2,'2005-09-01'),(3,'2005-09-30'),
2819
(4,'2005-10-01'),(5,'2005-12-30');
2820
select * from t1 where f2 >= 0            order by f2;
2821
f1	f2
2822
1	2005-01-01
2823
2	2005-09-01
2824
3	2005-09-30
2825
4	2005-10-01
2826
5	2005-12-30
2827
select * from t1 where f2 >= '0000-00-00' order by f2;
2828
f1	f2
2829
1	2005-01-01
2830
2	2005-09-01
2831
3	2005-09-30
2832
4	2005-10-01
2833
5	2005-12-30
2834
select * from t1 where f2 >= '2005-09-31' order by f2;
2835
f1	f2
2836
4	2005-10-01
2837
5	2005-12-30
2838
select * from t1 where f2 >= '2005-09-3a' order by f2;
2839
f1	f2
2840
3	2005-09-30
2841
4	2005-10-01
2842
5	2005-12-30
2843
Warnings:
2844
Warning	1292	Incorrect date value: '2005-09-3a' for column 'f2' at row 1
2845
select * from t1 where f2 <= '2005-09-31' order by f2;
2846
f1	f2
2847
1	2005-01-01
2848
2	2005-09-01
2849
3	2005-09-30
2850
select * from t1 where f2 <= '2005-09-3a' order by f2;
2851
f1	f2
2852
1	2005-01-01
2853
2	2005-09-01
2854
Warnings:
2855
Warning	1292	Incorrect date value: '2005-09-3a' for column 'f2' at row 1
2856
drop table t1;
2857
CREATE TABLE t1(key_a int4 NOT NULL, optimus varchar(32), PRIMARY KEY(key_a));
2858
CREATE TABLE t2(key_a int4 NOT NULL, prime varchar(32), PRIMARY KEY(key_a));
2859
CREATE table t3(key_a int4 NOT NULL, key_b int4 NOT NULL, foo varchar(32),
2860
PRIMARY KEY(key_a,key_b));
2861
INSERT INTO t1 VALUES (0,'');
2862
INSERT INTO t1 VALUES (1,'i');
2863
INSERT INTO t1 VALUES (2,'j');
2864
INSERT INTO t1 VALUES (3,'k');
2865
INSERT INTO t2 VALUES (1,'r');
2866
INSERT INTO t2 VALUES (2,'s');
2867
INSERT INTO t2 VALUES (3,'t');
2868
INSERT INTO t3 VALUES (1,5,'x');
2869
INSERT INTO t3 VALUES (1,6,'y');
2870
INSERT INTO t3 VALUES (2,5,'xx');
2871
INSERT INTO t3 VALUES (2,6,'yy');
2872
INSERT INTO t3 VALUES (2,7,'zz');
2873
INSERT INTO t3 VALUES (3,5,'xxx');
2874
SELECT t2.key_a,foo 
2875
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
2876
INNER JOIN t3 ON t1.key_a = t3.key_a
2877
WHERE t2.key_a=2 and key_b=5;
2878
key_a	foo
2879
2	xx
2880
EXPLAIN SELECT t2.key_a,foo 
2881
FROM t1 INNER JOIN t2 ON t1.key_a = t2.key_a
2882
INNER JOIN t3 ON t1.key_a = t3.key_a
2883
WHERE t2.key_a=2 and key_b=5;
2884
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2885
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
2886
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	Using index
2887
1	SIMPLE	t3	const	PRIMARY	PRIMARY	8	const,const	1	
2888
SELECT t2.key_a,foo 
2889
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
2890
INNER JOIN t3 ON t1.key_a = t3.key_a
2891
WHERE t2.key_a=2 and key_b=5;
2892
key_a	foo
2893
2	xx
2894
EXPLAIN SELECT t2.key_a,foo 
2895
FROM t1 INNER JOIN t2 ON t2.key_a = t1.key_a
2896
INNER JOIN t3 ON t1.key_a = t3.key_a
2897
WHERE t2.key_a=2 and key_b=5;
2898
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2899
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
2900
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	Using index
2901
1	SIMPLE	t3	const	PRIMARY	PRIMARY	8	const,const	1	
2902
DROP TABLE t1,t2,t3;
2903
create  table t1 (f1 int);
2904
insert into t1 values(1),(2);
2905
create table t2 (f2 int, f3 int, key(f2));
2906
insert into t2 values(1,1),(2,2);
2907
create table t3 (f4 int not null);
2908
insert into t3 values (2),(2),(2);
2909
select f1,(select count(*) from t2,t3 where f2=f1 and f3=f4) as count from t1;
2910
f1	count
2911
1	0
2912
2	3
2913
drop table t1,t2,t3;
2914
create table t1 (f1 int unique);
2915
create table t2 (f2 int unique);
2916
create table t3 (f3 int unique);
2917
insert into t1 values(1),(2);
2918
insert into t2 values(1),(2);
2919
insert into t3 values(1),(NULL);
2920
select * from t3 where f3 is null;
2921
f3
2922
NULL
2923
select t2.f2 from t1 left join t2 on f1=f2 join t3 on f1=f3 where f1=1;
2924
f2
2925
1
2926
drop table t1,t2,t3;
2927
create table t1(f1 char, f2 char not null);
2928
insert into t1 values(null,'a');
2929
create table t2 (f2 char not null);
2930
insert into t2 values('b');
2931
select * from t1 left join t2 on f1=t2.f2 where t1.f2='a';
2932
f1	f2	f2
2933
NULL	a	NULL
2934
drop table t1,t2;
2935
select * from (select * left join t on f1=f2) tt;
2936
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
2937
CREATE TABLE t1 (sku int PRIMARY KEY, pr int);
2938
CREATE TABLE t2 (sku int PRIMARY KEY, sppr int, name varchar(255));
2939
INSERT INTO t1 VALUES
2940
(10, 10), (20, 10), (30, 20), (40, 30), (50, 10), (60, 10);
2941
INSERT INTO t2 VALUES 
2942
(10, 10, 'aaa'), (20, 10, 'bbb'), (30, 10, 'ccc'), (40, 20, 'ddd'),
2943
(50, 10, 'eee'), (60, 20, 'fff'), (70, 20, 'ggg'), (80, 30, 'hhh');
2944
SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr
2945
FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku);
2946
sku	sppr	name	sku	pr
2947
20	10	bbb	10	10
2948
20	10	bbb	20	10
2949
EXPLAIN
2950
SELECT t2.sku, t2.sppr, t2.name, t1.sku, t1.pr
2951
FROM t2, t1 WHERE t2.sku=20 AND (t2.sku=t1.sku OR t2.sppr=t1.sku);
2952
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2953
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	
201 by Brian Aker
Convert default engine to Innodb
2954
1	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using where
1 by brian
clean slate
2955
DROP TABLE t1,t2;
2956
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
2957
INSERT t1 SET i = 0;
2958
UPDATE t1 SET i = -1;
2959
Warnings:
2960
Warning	1264	Out of range value for column 'i' at row 1
2961
SELECT * FROM t1;
2962
i
2963
0
2964
UPDATE t1 SET i = CAST(i - 1 AS SIGNED);
2965
Warnings:
2966
Warning	1264	Out of range value for column 'i' at row 1
2967
SELECT * FROM t1;
2968
i
2969
0
2970
UPDATE t1 SET i = i - 1;
2971
Warnings:
2972
Warning	1264	Out of range value for column 'i' at row 1
2973
SELECT * FROM t1;
2974
i
2975
255
2976
DROP TABLE t1;
2977
create table t1 (a int);
2978
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2979
create table t2 (a int, b int, c int, e int, primary key(a,b,c));
2980
insert into t2 select A.a, B.a, C.a, C.a from t1 A, t1 B, t1 C;
2981
analyze table t2;
2982
Table	Op	Msg_type	Msg_text
2983
test.t2	analyze	status	OK
2984
select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
2985
Z
2986
In next EXPLAIN, B.rows must be exactly 10:
2987
drop table t1, t2;
2988
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b));
2989
INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2),
2990
(3,1), (5,1), (8,9), (2,2), (0,9);
2991
CREATE TABLE t2 (c int, d int, f int, INDEX(c,f));
2992
INSERT INTO t2 VALUES
2993
(1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1),
2994
(5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1),
2995
(0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1);
2996
EXPLAIN
2997
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6;
2998
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
2999
1	SIMPLE	t1	range	PRIMARY,b	b	5	NULL	3	Using where; Using index
3000
1	SIMPLE	t2	ref	c	c	5	test.t1.a	1	
1 by brian
clean slate
3001
EXPLAIN
3002
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
3003
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3004
1	SIMPLE	t1	range	PRIMARY,b	b	5	NULL	3	Using where; Using index
3005
1	SIMPLE	t2	ref	c	c	5	test.t1.a	1	
1 by brian
clean slate
3006
DROP TABLE t1, t2;
3007
create table t1 (
3008
a int unsigned    not null auto_increment primary key,
3009
b bit             not null,
3010
c bit             not null
3011
);
3012
create table t2 (
3013
a int unsigned    not null auto_increment primary key,
3014
b bit             not null,
3015
c int unsigned    not null,
3016
d varchar(50)
3017
);
3018
insert into t1 (b,c) values (0,1), (0,1);
3019
insert into t2 (b,c) values (0,1);
3020
select t1.a, t1.b + 0, t1.c + 0, t2.a, t2.b + 0, t2.c, t2.d
3021
from t1 left outer join t2 on t1.a = t2.c and t2.b <> 1
3022
where t1.b <> 1 order by t1.a;
3023
a	t1.b + 0	t1.c + 0	a	t2.b + 0	c	d
3024
1	0	1	1	0	1	NULL
3025
2	0	1	NULL	NULL	NULL	NULL
3026
drop table t1,t2;
3027
SELECT 0.9888889889 * 1.011111411911;
3028
0.9888889889 * 1.011111411911
3029
0.9998769417899202067879
3030
CREATE TABLE t1 (a int NOT NULL PRIMARY KEY, b int NOT NULL);
3031
INSERT INTO t1 VALUES (1,1), (2,2), (3,3), (4,4);
3032
CREATE TABLE t2 (c int NOT NULL, INDEX idx(c));
3033
INSERT INTO t2 VALUES
3034
(1), (1), (1), (1), (1), (1), (1), (1),
3035
(2), (2), (2), (2),
3036
(3), (3),
3037
(4);
3038
EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=1;
3039
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3040
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3041
1	SIMPLE	t2	ref	idx	idx	4	const	7	Using index
3042
EXPLAIN SELECT b FROM t1, t2 WHERE b=c AND a=4;
3043
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3044
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3045
1	SIMPLE	t2	ref	idx	idx	4	const	1	Using index
3046
DROP TABLE t1, t2;
3047
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a int);
3048
INSERT INTO t1 VALUES (1,2), (2,NULL), (3,2);
3049
CREATE TABLE t2 (b int, c INT, INDEX idx1(b));
3050
INSERT INTO t2 VALUES (2,1), (3,2);
3051
CREATE TABLE t3 (d int,  e int, INDEX idx1(d));
3052
INSERT INTO t3 VALUES (2,10), (2,20), (1,30), (2,40), (2,50);
3053
EXPLAIN
3054
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
3055
WHERE t1.id=2;
3056
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3057
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3058
1	SIMPLE	t2	const	idx1	NULL	NULL	NULL	1	
201 by Brian Aker
Convert default engine to Innodb
3059
1	SIMPLE	t3	ref	idx1	idx1	5	const	2	
1 by brian
clean slate
3060
SELECT * FROM t1 LEFT JOIN t2 ON t2.b=t1.a INNER JOIN t3 ON t3.d=t1.id
3061
WHERE t1.id=2;
3062
id	a	b	c	d	e
3063
2	NULL	NULL	NULL	2	10
3064
2	NULL	NULL	NULL	2	20
3065
2	NULL	NULL	NULL	2	40
3066
2	NULL	NULL	NULL	2	50
3067
DROP TABLE t1,t2,t3;
3068
CREATE TABLE t1 (pk varchar(10) PRIMARY KEY, fk varchar(16));
3069
CREATE TABLE t2 (pk varchar(16) PRIMARY KEY, fk varchar(10));
3070
INSERT INTO t1 VALUES
3071
('d','dddd'), ('i','iii'), ('a','aa'), ('b','bb'), ('g','gg'), 
3072
('e','eee'), ('c','cccc'), ('h','hhh'), ('j','jjj'), ('f','fff');
3073
INSERT INTO t2 VALUES
3074
('jjj', 'j'), ('cc','c'), ('ccc','c'), ('aaa', 'a'), ('jjjj','j'),
3075
('hhh','h'), ('gg','g'), ('fff','f'), ('ee','e'), ('ffff','f'),
3076
('bbb','b'), ('ff','f'), ('cccc','c'), ('dddd','d'), ('jj','j'),
3077
('aaaa','a'), ('bb','b'), ('eeee','e'), ('aa','a'), ('hh','h');
3078
EXPLAIN SELECT t2.* 
3079
FROM t1 JOIN t2 ON t2.fk=t1.pk
3080
WHERE t2.fk < 'c' AND t2.pk=t1.fk;
3081
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3082
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using where
1 by brian
clean slate
3083
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
3084
EXPLAIN SELECT t2.* 
3085
FROM t1 JOIN t2 ON t2.fk=t1.pk 
3086
WHERE t2.fk BETWEEN 'a' AND 'b' AND t2.pk=t1.fk;
3087
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3088
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using where
1 by brian
clean slate
3089
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
3090
EXPLAIN SELECT t2.* 
3091
FROM t1 JOIN t2 ON t2.fk=t1.pk 
3092
WHERE t2.fk IN ('a','b') AND t2.pk=t1.fk;
3093
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3094
1	SIMPLE	t1	range	PRIMARY	PRIMARY	12	NULL	2	Using where
1 by brian
clean slate
3095
1	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	18	test.t1.fk	1	Using where
3096
DROP TABLE t1,t2;
3097
CREATE TABLE t1 (a int, b varchar(20) NOT NULL, PRIMARY KEY(a));
3098
CREATE TABLE t2 (a int, b varchar(20) NOT NULL,
3099
PRIMARY KEY (a), UNIQUE KEY (b));
3100
INSERT INTO t1 VALUES (1,'a'),(2,'b'),(3,'c');
3101
INSERT INTO t2 VALUES (1,'a'),(2,'b'),(3,'c');
3102
EXPLAIN SELECT t1.a FROM t1 LEFT JOIN t2 ON t2.b=t1.b WHERE t1.a=3;
3103
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3104
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3105
1	SIMPLE	t2	const	b	b	22	const	1	Using index
3106
DROP TABLE t1,t2;
3107
CREATE TABLE t1(id int PRIMARY KEY, b int, e int);
3108
CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a));
3109
CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c));
3110
INSERT INTO t1 VALUES 
3111
(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79),
3112
(6,63,67), (5,55,58), (3,38,39), (8,81,89);
3113
INSERT INTO t2 VALUES
3114
(21,210), (41,410), (82,820), (83,830), (84,840),
3115
(65,650), (51,510), (37,370), (94,940), (76,760),
3116
(22,220), (33,330), (40,400), (95,950), (38,380),
3117
(67,670), (88,880), (57,570), (96,960), (97,970);
3118
INSERT INTO t3 VALUES
3119
(210,'bb'), (950,'ii'), (400,'ab'), (500,'ee'), (220,'gg'),
3120
(440,'gg'), (310,'eg'), (380,'ee'), (840,'bb'), (830,'ff'),
3121
(230,'aa'), (960,'ii'), (410,'aa'), (510,'ee'), (290,'bb'),
3122
(450,'gg'), (320,'dd'), (390,'hh'), (850,'jj'), (860,'ff');
3123
EXPLAIN
3124
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
3125
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND 
3126
t3.a=t2.a AND t3.c IN ('bb','ee');
3127
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3128
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3129
1	SIMPLE	t2	range	si	si	5	NULL	4	Using index condition; Using MRR
3130
1	SIMPLE	t3	eq_ref	PRIMARY,ci	PRIMARY	4	test.t2.a	1	Using where
3131
EXPLAIN
3132
SELECT t3.a FROM t1,t2,t3
3133
WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND
3134
t3.a=t2.a AND t3.c IN ('bb','ee') ;
3135
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3136
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
201 by Brian Aker
Convert default engine to Innodb
3137
1	SIMPLE	t3	range	PRIMARY,ci	ci	5	NULL	6	Using where; Using index
3138
1	SIMPLE	t2	ref	si,ai	ai	5	test.t3.a	1	Using where
1 by brian
clean slate
3139
EXPLAIN 
3140
SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3
3141
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
3142
t3.c IN ('bb','ee');
3143
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3144
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3145
1	SIMPLE	t2	range	si	si	5	NULL	2	Using index condition; Using MRR
3146
1	SIMPLE	t3	eq_ref	PRIMARY,ci	PRIMARY	4	test.t2.a	1	Using where
3147
EXPLAIN 
3148
SELECT t3.a FROM t1,t2,t3
3149
WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND
3150
t3.c IN ('bb','ee');
3151
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3152
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	
3153
1	SIMPLE	t2	range	si,ai	si	5	NULL	2	Using index condition; Using MRR
3154
1	SIMPLE	t3	eq_ref	PRIMARY,ci	PRIMARY	4	test.t2.a	1	Using where
3155
DROP TABLE t1,t2,t3;
3156
CREATE TABLE t1 ( f1 int primary key, f2 int, f3 int, f4 int, f5 int, f6 int, checked_out int);
3157
CREATE TABLE t2 ( f11 int PRIMARY KEY );
3158
INSERT INTO t1 VALUES (1,1,1,0,0,0,0),(2,1,1,3,8,1,0),(3,1,1,4,12,1,0);
3159
INSERT INTO t2 VALUES (62);
3160
SELECT * FROM t1 LEFT JOIN t2 ON f11 = t1.checked_out GROUP BY f1 ORDER BY f2, f3, f4, f5 LIMIT 0, 1;
3161
f1	f2	f3	f4	f5	f6	checked_out	f11
3162
1	1	1	0	0	0	0	NULL
3163
DROP TABLE t1, t2;
3164
DROP TABLE IF EXISTS t1;
3165
CREATE TABLE t1(a int);
3166
INSERT into t1 values (1), (2), (3);
3167
SELECT * FROM t1 LIMIT 2, -1;
3168
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 '-1' at line 1
3169
DROP TABLE t1;
3170
CREATE TABLE t1 (
3171
ID_with_null int NULL,
3172
ID_better int NOT NULL,
3173
INDEX idx1 (ID_with_null),
3174
INDEX idx2 (ID_better)
3175
);
3176
INSERT INTO t1 VALUES (1,1), (2,1), (null,3), (null,3), (null,3), (null,3);
3177
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
3178
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
3179
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
3180
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
3181
INSERT INTO t1 SELECT * FROM t1 WHERE ID_with_null IS NULL;
3182
SELECT COUNT(*) FROM t1 WHERE ID_with_null IS NULL;
3183
COUNT(*)
3184
128
3185
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
3186
COUNT(*)
3187
2
3188
EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID_with_null IS NULL;
3189
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3190
1	SIMPLE	t1	index_merge	idx1,idx2	idx2,idx1	4,5	NULL	1	Using intersect(idx2,idx1); Using where; Using index
1 by brian
clean slate
3191
DROP INDEX idx1 ON t1;
3192
CREATE UNIQUE INDEX idx1 ON t1(ID_with_null);
3193
EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID_with_null IS NULL;
3194
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3195
1	SIMPLE	t1	index_merge	idx1,idx2	idx2,idx1	4,5	NULL	1	Using intersect(idx2,idx1); Using where; Using index
1 by brian
clean slate
3196
DROP TABLE t1;
3197
CREATE TABLE t1 (
3198
ID1_with_null int NULL,
3199
ID2_with_null int NULL,
3200
ID_better int NOT NULL,
3201
INDEX idx1 (ID1_with_null, ID2_with_null),
3202
INDEX idx2 (ID_better)
3203
);
3204
INSERT INTO t1 VALUES (1,1,1), (2,2,1), (3,null,3), (null,3,3), (null,null,3),
3205
(3,null,3), (null,3,3), (null,null,3), (3,null,3), (null,3,3), (null,null,3);
3206
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
3207
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
3208
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
3209
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
3210
INSERT INTO t1 SELECT * FROM t1 WHERE ID1_with_null IS NULL;
3211
INSERT INTO t1 SELECT * FROM t1 WHERE ID2_with_null IS NULL;
3212
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null=3;
3213
COUNT(*)
3214
24
3215
SELECT COUNT(*) FROM t1 WHERE ID1_with_null=3 AND ID2_with_null IS NULL;
3216
COUNT(*)
3217
24
3218
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null IS NULL;
3219
COUNT(*)
3220
192
3221
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
3222
COUNT(*)
3223
2
3224
EXPLAIN SELECT * FROM t1
3225
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
3226
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3227
1	SIMPLE	t1	index_merge	idx1,idx2	idx2,idx1	4,10	NULL	1	Using intersect(idx2,idx1); Using where; Using index
1 by brian
clean slate
3228
EXPLAIN SELECT * FROM t1
3229
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
3230
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3231
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
1 by brian
clean slate
3232
EXPLAIN SELECT * FROM t1
3233
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
3234
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3235
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
1 by brian
clean slate
3236
DROP INDEX idx1 ON t1;
3237
CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null);
3238
EXPLAIN SELECT * FROM t1
3239
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
3240
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3241
1	SIMPLE	t1	index_merge	idx1,idx2	idx2,idx1	4,10	NULL	1	Using intersect(idx2,idx1); Using where; Using index
1 by brian
clean slate
3242
EXPLAIN SELECT * FROM t1
3243
WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ;
3244
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3245
1	SIMPLE	t1	index_merge	idx1,idx2	idx2,idx1	4,10	NULL	1	Using intersect(idx2,idx1); Using where; Using index
1 by brian
clean slate
3246
EXPLAIN SELECT * FROM t1
3247
WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
3248
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3249
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
1 by brian
clean slate
3250
EXPLAIN SELECT * FROM t1
3251
WHERE ID_better=1 AND ID1_with_null IS NULL AND 
3252
(ID2_with_null=1 OR ID2_with_null=2);
3253
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3254
1	SIMPLE	t1	ref	idx1,idx2	idx2	4	const	2	Using where
1 by brian
clean slate
3255
DROP TABLE t1;
3256
CREATE TABLE t1 (a INT, ts TIMESTAMP, KEY ts(ts));
3257
INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00");
3258
ANALYZE TABLE t1;
3259
Table	Op	Msg_type	Msg_text
3260
test.t1	analyze	status	OK
3261
CREATE TABLE t2 (a INT, dt1 DATETIME, dt2 DATETIME, PRIMARY KEY (a));
3262
INSERT INTO t2 VALUES (30, "2006-01-01 00:00:00", "2999-12-31 00:00:00");
3263
INSERT INTO t2 SELECT a+1,dt1,dt2 FROM t2;
3264
ANALYZE TABLE t2;
3265
Table	Op	Msg_type	Msg_text
3266
test.t2	analyze	status	OK
3267
EXPLAIN
3268
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
3269
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
3270
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
3271
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3272
1	SIMPLE	t2	const	PRIMARY	PRIMARY	4	const	1	
3273
1	SIMPLE	t1	range	ts	ts	4	NULL	1	Using index condition; Using where; Using MRR
3274
Warnings:
3275
Warning	1292	Incorrect datetime value: '2999-12-31 00:00:00' for column 'ts' at row 1
3276
SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30
3277
AND t1.ts BETWEEN t2.dt1 AND t2.dt2
3278
AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
3279
a	ts	a	dt1	dt2
3280
30	2006-01-03 23:00:00	30	2006-01-01 00:00:00	2999-12-31 00:00:00
3281
Warnings:
3282
Warning	1292	Incorrect datetime value: '2999-12-31 00:00:00' for column 'ts' at row 1
3283
DROP TABLE t1,t2;
3284
create table t1 (a bigint unsigned);
3285
insert into t1 values
3286
(if(1, 9223372036854775808, 1)),
3287
(case when 1 then 9223372036854775808 else 1 end),
3288
(coalesce(9223372036854775808, 1));
3289
select * from t1;
3290
a
3291
9223372036854775808
3292
9223372036854775808
3293
9223372036854775808
3294
drop table t1;
3295
create table t1 select
3296
if(1, 9223372036854775808, 1) i,
3297
case when 1 then 9223372036854775808 else 1 end c,
3298
coalesce(9223372036854775808, 1) co;
3299
show create table t1;
3300
Table	Create Table
3301
t1	CREATE TABLE "t1" (
3302
  "i" decimal(19,0) NOT NULL,
3303
  "c" decimal(19,0) NOT NULL,
3304
  "co" decimal(19,0) NOT NULL
201 by Brian Aker
Convert default engine to Innodb
3305
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 by brian
clean slate
3306
drop table t1;
3307
select 
3308
if(1, cast(1111111111111111111 as unsigned), 1) i,
3309
case when 1 then cast(1111111111111111111 as unsigned) else 1 end c,
3310
coalesce(cast(1111111111111111111 as unsigned), 1) co;
3311
i	c	co
3312
1111111111111111111	1111111111111111111	1111111111111111111
3313
CREATE TABLE t1 (name varchar(255));
3314
CREATE TABLE t2 (name varchar(255), n int, KEY (name(3)));
3315
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
3316
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
3317
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
3318
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
3319
SELECT * FROM t2;
3320
name	n
3321
bb	1
3322
aa	2
3323
cc   	3
3324
cc 	4
3325
cc	5
3326
bb 	6
3327
cc 	7
3328
SELECT * FROM t2 ORDER BY name;
3329
name	n
3330
aa	2
3331
bb	1
3332
bb 	6
3333
cc 	4
3334
cc   	3
3335
cc	5
3336
cc 	7
3337
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
3338
name	LENGTH(name)	n
3339
aa	2	2
3340
bb	2	1
3341
bb 	3	6
3342
cc 	4	4
3343
cc   	5	3
3344
cc	2	5
3345
cc 	3	7
3346
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
3347
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3348
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where
1 by brian
clean slate
3349
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
3350
name	LENGTH(name)	n
3351
cc   	5	3
3352
cc	2	5
3353
cc 	3	7
3354
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
3355
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3356
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where
1 by brian
clean slate
3357
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
3358
name	LENGTH(name)	n
3359
cc   	5	3
3360
cc 	4	4
3361
cc	2	5
3362
cc 	3	7
3363
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
3364
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3365
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where; Using filesort
1 by brian
clean slate
3366
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
3367
name	LENGTH(name)	n
3368
cc 	4	4
3369
cc   	5	3
3370
cc	2	5
3371
cc 	3	7
3372
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
3373
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3374
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
201 by Brian Aker
Convert default engine to Innodb
3375
1	SIMPLE	t2	ref	name	name	6	test.t1.name	1	
1 by brian
clean slate
3376
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
3377
name	name	n
3378
ccc	NULL	NULL
3379
bb	bb	1
3380
bb	bb 	6
3381
cc 	cc   	3
3382
cc 	cc	5
3383
cc 	cc 	7
3384
aa  	aa	2
3385
aa	aa	2
3386
DROP TABLE t1,t2;
3387
CREATE TABLE t1 (name text);
3388
CREATE TABLE t2 (name text, n int, KEY (name(3)));
3389
INSERT INTO t1 VALUES ('ccc'), ('bb'), ('cc '), ('aa  '), ('aa');
3390
INSERT INTO t2 VALUES ('bb',1), ('aa',2), ('cc   ',3);
3391
INSERT INTO t2 VALUES (concat('cc ', 0x06), 4);
3392
INSERT INTO t2 VALUES ('cc',5), ('bb ',6), ('cc ',7);
3393
SELECT * FROM t2;
3394
name	n
3395
bb	1
3396
aa	2
3397
cc   	3
3398
cc 	4
3399
cc	5
3400
bb 	6
3401
cc 	7
3402
SELECT * FROM t2 ORDER BY name;
3403
name	n
3404
aa	2
3405
bb	1
3406
bb 	6
3407
cc 	4
3408
cc   	3
3409
cc	5
3410
cc 	7
3411
SELECT name, LENGTH(name), n FROM t2 ORDER BY name;
3412
name	LENGTH(name)	n
3413
aa	2	2
3414
bb	2	1
3415
bb 	3	6
3416
cc 	4	4
3417
cc   	5	3
3418
cc	2	5
3419
cc 	3	7
3420
EXPLAIN SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
3421
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3422
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where
1 by brian
clean slate
3423
SELECT name, LENGTH(name), n FROM t2 WHERE name='cc ';
3424
name	LENGTH(name)	n
3425
cc   	5	3
3426
cc	2	5
3427
cc 	3	7
3428
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
3429
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3430
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where
1 by brian
clean slate
3431
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%';
3432
name	LENGTH(name)	n
3433
cc   	5	3
3434
cc 	4	4
3435
cc	2	5
3436
cc 	3	7
3437
EXPLAIN SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
3438
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
201 by Brian Aker
Convert default engine to Innodb
3439
1	SIMPLE	t2	ALL	name	NULL	NULL	NULL	7	Using where; Using filesort
1 by brian
clean slate
3440
SELECT name , LENGTH(name), n FROM t2 WHERE name LIKE 'cc%' ORDER BY name;
3441
name	LENGTH(name)	n
3442
cc 	4	4
3443
cc   	5	3
3444
cc	2	5
3445
cc 	3	7
3446
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
3447
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3448
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	
201 by Brian Aker
Convert default engine to Innodb
3449
1	SIMPLE	t2	ref	name	name	6	test.t1.name	1	
1 by brian
clean slate
3450
SELECT * FROM t1 LEFT JOIN t2 ON t1.name=t2.name;
3451
name	name	n
3452
ccc	NULL	NULL
3453
bb	bb	1
3454
bb	bb 	6
3455
cc 	cc   	3
3456
cc 	cc	5
3457
cc 	cc 	7
3458
aa  	aa	2
3459
aa	aa	2
3460
DROP TABLE t1,t2;
3461
CREATE TABLE t1 (
3462
access_id int NOT NULL default '0',
3463
name varchar(20) default NULL,
3464
rank int NOT NULL default '0',
3465
KEY idx (access_id)
3466
);
3467
CREATE TABLE t2 (
3468
faq_group_id int NOT NULL default '0',
3469
faq_id int NOT NULL default '0',
3470
access_id int default NULL,
3471
UNIQUE KEY idx1 (faq_id),
3472
KEY idx2 (faq_group_id,faq_id)
3473
);
3474
INSERT INTO t1 VALUES 
3475
(1,'Everyone',2),(2,'Help',3),(3,'Technical Support',1),(4,'Chat User',4);
3476
INSERT INTO t2 VALUES
3477
(261,265,1),(490,494,1);
3478
SELECT t2.faq_id 
3479
FROM t1 INNER JOIN t2 IGNORE INDEX (idx1)
3480
ON (t1.access_id = t2.access_id)
3481
LEFT JOIN t2 t
3482
ON (t.faq_group_id = t2.faq_group_id AND
3483
find_in_set(t.access_id, '1,4') < find_in_set(t2.access_id, '1,4'))
3484
WHERE
3485
t2.access_id IN (1,4) AND t.access_id IS NULL AND t2.faq_id in (265);
3486
faq_id
3487
265
3488
SELECT t2.faq_id 
3489
FROM t1 INNER JOIN t2
3490
ON (t1.access_id = t2.access_id)
3491
LEFT JOIN t2 t
3492
ON (t.faq_group_id = t2.faq_group_id AND
3493
find_in_set(t.access_id, '1,4') < find_in_set(t2.access_id, '1,4'))
3494
WHERE
3495
t2.access_id IN (1,4) AND t.access_id IS NULL AND t2.faq_id in (265);
3496
faq_id
3497
265
3498
DROP TABLE t1,t2;
3499
CREATE TABLE t1 (a INT, b INT, KEY inx (b,a));
3500
INSERT INTO t1 VALUES (1,1), (1,2), (1,3), (1,4), (1,5), (1, 6), (1,7);
3501
EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2
3502
ON ( f1.b=f2.b AND f1.a<f2.a ) 
3503
WHERE 1 AND f1.b NOT IN (100,2232,3343,51111);
3504
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3505
1	SIMPLE	f1	index	inx	inx	10	NULL	7	Using where; Using index
201 by Brian Aker
Convert default engine to Innodb
3506
1	SIMPLE	f2	ref	inx	inx	5	test.f1.b	3	Using where; Using index
1 by brian
clean slate
3507
DROP TABLE t1;
3508
CREATE TABLE t1 (c1 INT, c2 INT);
3509
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
3510
EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2)))))))))))))))))))))))))))))))) > 0;
3511
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3512
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
3513
31	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
3514
32	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
3515
EXPLAIN SELECT c1 FROM t1 WHERE (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT (SELECT COUNT(c2))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) > 0;
3516
ERROR HY000: Too high level of nesting for select
3517
DROP TABLE t1;
3518
CREATE TABLE t1 (
3519
c1 int(11) NOT NULL AUTO_INCREMENT,
3520
c2 varchar(1000) DEFAULT NULL,
3521
c3 bigint(20) DEFAULT NULL,
3522
c4 bigint(20) DEFAULT NULL,
3523
PRIMARY KEY (c1)
3524
);
3525
EXPLAIN EXTENDED 
3526
SELECT  join_2.c1  
3527
FROM 
3528
t1 AS join_0, 
3529
t1 AS join_1, 
3530
t1 AS join_2, 
3531
t1 AS join_3, 
3532
t1 AS join_4, 
3533
t1 AS join_5, 
3534
t1 AS join_6, 
3535
t1 AS join_7
3536
WHERE 
3537
join_0.c1=join_1.c1  AND 
3538
join_1.c1=join_2.c1  AND 
3539
join_2.c1=join_3.c1  AND 
3540
join_3.c1=join_4.c1  AND 
3541
join_4.c1=join_5.c1  AND 
3542
join_5.c1=join_6.c1  AND 
3543
join_6.c1=join_7.c1 
3544
OR 
3545
join_0.c2 < '?'  AND 
3546
join_1.c2 < '?'  AND
3547
join_2.c2 > '?'  AND
3548
join_2.c2 < '!'  AND
3549
join_3.c2 > '?'  AND 
3550
join_4.c2 = '?'  AND 
3551
join_5.c2 <> '?' AND
3552
join_6.c2 <> '?' AND 
3553
join_7.c2 >= '?' AND
3554
join_0.c1=join_1.c1  AND 
3555
join_1.c1=join_2.c1  AND 
3556
join_2.c1=join_3.c1  AND
3557
join_3.c1=join_4.c1  AND 
3558
join_4.c1=join_5.c1  AND 
3559
join_5.c1=join_6.c1  AND 
3560
join_6.c1=join_7.c1
3561
GROUP BY 
3562
join_3.c1,
3563
join_2.c1,
3564
join_7.c1,
3565
join_1.c1,
3566
join_0.c1;
3567
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
201 by Brian Aker
Convert default engine to Innodb
3568
1	SIMPLE	join_0	ALL	PRIMARY	NULL	NULL	NULL	1	100.00	Using temporary; Using filesort
3569
1	SIMPLE	join_1	eq_ref	PRIMARY	PRIMARY	4	test.join_0.c1	1	100.00	
3570
1	SIMPLE	join_2	eq_ref	PRIMARY	PRIMARY	4	test.join_1.c1	1	100.00	Using where
3571
1	SIMPLE	join_3	eq_ref	PRIMARY	PRIMARY	4	test.join_2.c1	1	100.00	Using where
3572
1	SIMPLE	join_4	eq_ref	PRIMARY	PRIMARY	4	test.join_3.c1	1	100.00	Using where
3573
1	SIMPLE	join_5	eq_ref	PRIMARY	PRIMARY	4	test.join_4.c1	1	100.00	Using where
3574
1	SIMPLE	join_6	eq_ref	PRIMARY	PRIMARY	4	test.join_5.c1	1	100.00	Using where
3575
1	SIMPLE	join_7	eq_ref	PRIMARY	PRIMARY	4	test.join_5.c1	1	100.00	Using where
1 by brian
clean slate
3576
Warnings:
201 by Brian Aker
Convert default engine to Innodb
3577
Note	1003	select "test"."join_2"."c1" AS "c1" from "test"."t1" "join_0" join "test"."t1" "join_1" join "test"."t1" "join_2" join "test"."t1" "join_3" join "test"."t1" "join_4" join "test"."t1" "join_5" join "test"."t1" "join_6" join "test"."t1" "join_7" where ((("test"."join_1"."c1" = "test"."join_0"."c1") and ("test"."join_2"."c1" = "test"."join_0"."c1") and ("test"."join_3"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c1" = "test"."join_0"."c1") and ("test"."join_5"."c1" = "test"."join_0"."c1") and ("test"."join_6"."c1" = "test"."join_0"."c1") and ("test"."join_7"."c1" = "test"."join_0"."c1")) or (("test"."join_1"."c1" = "test"."join_0"."c1") and ("test"."join_2"."c1" = "test"."join_0"."c1") and ("test"."join_3"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c1" = "test"."join_0"."c1") and ("test"."join_5"."c1" = "test"."join_0"."c1") and ("test"."join_6"."c1" = "test"."join_0"."c1") and ("test"."join_7"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c2" = '?') and ("test"."join_0"."c2" < '?') and ("test"."join_1"."c2" < '?') and ("test"."join_2"."c2" > '?') and ("test"."join_2"."c2" < '!') and ("test"."join_3"."c2" > '?') and ("test"."join_5"."c2" <> '?') and ("test"."join_6"."c2" <> '?') and ("test"."join_7"."c2" >= '?'))) group by "test"."join_3"."c1","test"."join_2"."c1","test"."join_1"."c1","test"."join_0"."c1"
1 by brian
clean slate
3578
SHOW WARNINGS;
3579
Level	Code	Message
201 by Brian Aker
Convert default engine to Innodb
3580
Note	1003	select "test"."join_2"."c1" AS "c1" from "test"."t1" "join_0" join "test"."t1" "join_1" join "test"."t1" "join_2" join "test"."t1" "join_3" join "test"."t1" "join_4" join "test"."t1" "join_5" join "test"."t1" "join_6" join "test"."t1" "join_7" where ((("test"."join_1"."c1" = "test"."join_0"."c1") and ("test"."join_2"."c1" = "test"."join_0"."c1") and ("test"."join_3"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c1" = "test"."join_0"."c1") and ("test"."join_5"."c1" = "test"."join_0"."c1") and ("test"."join_6"."c1" = "test"."join_0"."c1") and ("test"."join_7"."c1" = "test"."join_0"."c1")) or (("test"."join_1"."c1" = "test"."join_0"."c1") and ("test"."join_2"."c1" = "test"."join_0"."c1") and ("test"."join_3"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c1" = "test"."join_0"."c1") and ("test"."join_5"."c1" = "test"."join_0"."c1") and ("test"."join_6"."c1" = "test"."join_0"."c1") and ("test"."join_7"."c1" = "test"."join_0"."c1") and ("test"."join_4"."c2" = '?') and ("test"."join_0"."c2" < '?') and ("test"."join_1"."c2" < '?') and ("test"."join_2"."c2" > '?') and ("test"."join_2"."c2" < '!') and ("test"."join_3"."c2" > '?') and ("test"."join_5"."c2" <> '?') and ("test"."join_6"."c2" <> '?') and ("test"."join_7"."c2" >= '?'))) group by "test"."join_3"."c1","test"."join_2"."c1","test"."join_1"."c1","test"."join_0"."c1"
1 by brian
clean slate
3581
DROP TABLE t1;
3582
SELECT 1 AS ` `;
3583
3584
1
3585
Warnings:
3586
Warning	1474	Name ' ' has become ''
3587
SELECT 1 AS `  `;
3588
3589
1
3590
Warnings:
3591
Warning	1474	Name '  ' has become ''
3592
SELECT 1 AS ` x`;
3593
x
3594
1
3595
Warnings:
3596
Warning	1466	Leading spaces are removed from name ' x'
3597
CREATE TABLE t1 (c11 INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
3598
CREATE TABLE t2 (c21 INT UNSIGNED NOT NULL, 
3599
c22 INT DEFAULT NULL, 
3600
KEY(c21, c22));
3601
CREATE TABLE t3 (c31 INT UNSIGNED NOT NULL DEFAULT 0, 
3602
c32 INT DEFAULT NULL, 
3603
c33 INT NOT NULL, 
3604
c34 INT UNSIGNED DEFAULT 0,
3605
KEY (c33, c34, c32));
3606
INSERT INTO t1 values (),(),(),(),();
3607
INSERT INTO t2 SELECT a.c11, b.c11 FROM t1 a, t1 b;
3608
INSERT INTO t3 VALUES (1, 1, 1, 0), 
3609
(2, 2, 0, 0), 
3610
(3, 3, 1, 0), 
3611
(4, 4, 0, 0), 
3612
(5, 5, 1, 0);
3613
SELECT c32 FROM t1, t2, t3 WHERE t1.c11 IN (1, 3, 5) AND 
3614
t3.c31 = t1.c11 AND t2.c21 = t1.c11 AND 
3615
t3.c33 = 1 AND t2.c22 in (1, 3) 
3616
ORDER BY c32;
3617
c32
3618
1
3619
1
3620
3
3621
3
3622
5
3623
5
3624
SELECT c32 FROM t1, t2, t3 WHERE t1.c11 IN (1, 3, 5) AND 
3625
t3.c31 = t1.c11 AND t2.c21 = t1.c11 AND 
3626
t3.c33 = 1 AND t2.c22 in (1, 3) 
3627
ORDER BY c32 DESC;
3628
c32
3629
5
3630
5
3631
3
3632
3
3633
1
3634
1
3635
DROP TABLE t1, t2, t3;
3636
select str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3637
                                                and '2007/10/20 00:00:00 GMT';
3638
str_to_date('2007-10-09','%Y-%m-%d') between '2007/10/01 00:00:00 GMT'
3639
                                                and '2007/10/20 00:00:00 GMT'
3640
1
3641
Warnings:
3642
Warning	1292	Truncated incorrect datetime value: '2007/10/01 00:00:00 GMT'
3643
Warning	1292	Truncated incorrect datetime value: '2007/10/20 00:00:00 GMT'
3644
select str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6';
3645
str_to_date('2007-10-09','%Y-%m-%d') > '2007/10/01 00:00:00 GMT-6'
3646
1
3647
Warnings:
3648
Warning	1292	Truncated incorrect date value: '2007/10/01 00:00:00 GMT-6'
3649
select str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6';
3650
str_to_date('2007-10-09','%Y-%m-%d') <= '2007/10/2000:00:00 GMT-6'
3651
1
3652
Warnings:
3653
Warning	1292	Truncated incorrect date value: '2007/10/2000:00:00 GMT-6'
3654
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6';
3655
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-1 00:00:00 GMT-6'
3656
1
3657
Warnings:
3658
Warning	1292	Truncated incorrect date value: '2007-10-1 00:00:00 GMT-6'
3659
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6';
3660
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 x00:00:00 GMT-6'
3661
1
3662
Warnings:
3663
Warning	1292	Truncated incorrect date value: '2007-10-01 x00:00:00 GMT-6'
3664
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6';
3665
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:00:00 GMT-6'
3666
1
3667
Warnings:
3668
Warning	1292	Truncated incorrect datetime value: '2007-10-01 00:00:00 GMT-6'
3669
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6';
3670
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 00:x00:00 GMT-6'
3671
1
3672
Warnings:
3673
Warning	1292	Truncated incorrect datetime value: '2007-10-01 00:x00:00 GMT-6'
3674
select str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6';
3675
str_to_date('2007-10-01','%Y-%m-%d %H:%i:%s') = '2007-10-01 x12:34:56 GMT-6'
3676
1
3677
Warnings:
3678
Warning	1292	Truncated incorrect datetime value: '2007-10-01 x12:34:56 GMT-6'
3679
select str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3680
str_to_date('2007-10-01 12:34:00','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6'
3681
1
3682
Warnings:
3683
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34x:56 GMT-6'
3684
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6';
3685
str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34x:56 GMT-6'
3686
0
3687
Warnings:
3688
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34x:56 GMT-6'
3689
select str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56';
3690
str_to_date('2007-10-01 12:34:56','%Y-%m-%d %H:%i:%s') = '2007-10-01 12:34:56'
3691
1
3692
select str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00';
3693
str_to_date('2007-10-01','%Y-%m-%d') = '2007-10-01 12:00:00'
3694
0
3695
select str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3696
str_to_date('2007-10-01 12','%Y-%m-%d %H') = '2007-10-01 12:00:00'
3697
1
3698
select str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00';
3699
str_to_date('2007-10-01 12:34','%Y-%m-%d %H') = '2007-10-01 12:00:00'
3700
1
3701
Warnings:
3702
Warning	1292	Truncated incorrect datetime value: '2007-10-01 12:34'
3703
select str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34';
3704
str_to_date('2007-02-30 12:34','%Y-%m-%d %H:%i') = '2007-02-30 12:34'
3705
1
3706
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34';
3707
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '2007-10-00 12:34'
3708
1
3709
select str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3710
                                                and '2007/10/20 00:00:00';
3711
str_to_date('2007-10-00','%Y-%m-%d') between '2007/09/01 00:00:00'
3712
                                                and '2007/10/20 00:00:00'
3713
1
3714
select str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20';
3715
str_to_date('2007-10-00','%Y-%m-%d') between '' and '2007/10/20'
3716
1
3717
Warnings:
3718
Warning	1292	Truncated incorrect datetime value: ''
3719
select str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20';
3720
str_to_date('','%Y-%m-%d') between '2007/10/01' and '2007/10/20'
3721
0
3722
select str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3723
str_to_date('','%Y-%m-%d %H:%i') = '2007-10-01 12:34'
3724
0
3725
select str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34';
3726
str_to_date(NULL,'%Y-%m-%d %H:%i') = '2007-10-01 12:34'
3727
NULL
3728
select str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = '';
3729
str_to_date('2007-10-00 12:34','%Y-%m-%d %H:%i') = ''
3730
0
3731
Warnings:
3732
Warning	1292	Truncated incorrect datetime value: ''
3733
select str_to_date('1','%Y-%m-%d') = '1';
3734
str_to_date('1','%Y-%m-%d') = '1'
3735
0
3736
Warnings:
3737
Warning	1292	Truncated incorrect date value: '1'
3738
select str_to_date('1','%Y-%m-%d') = '1';
3739
str_to_date('1','%Y-%m-%d') = '1'
3740
0
3741
Warnings:
3742
Warning	1292	Truncated incorrect date value: '1'
3743
select str_to_date('','%Y-%m-%d') = '';
3744
str_to_date('','%Y-%m-%d') = ''
3745
0
3746
Warnings:
3747
Warning	1292	Truncated incorrect date value: ''
3748
select str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL;
3749
str_to_date('1000-01-01','%Y-%m-%d') between '0000-00-00' and NULL
3750
0
3751
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00';
3752
str_to_date('1000-01-01','%Y-%m-%d') between NULL and '2000-00-00'
3753
0
3754
select str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL;
3755
str_to_date('1000-01-01','%Y-%m-%d') between NULL and NULL
3756
0
3757
3758
#
3759
# Bug#30736: Row Size Too Large Error Creating a Table and
3760
# Inserting Data.
3761
#
3762
DROP TABLE IF EXISTS t1;
3763
DROP TABLE IF EXISTS t2;
3764
3765
CREATE TABLE t1(
3766
c1 DECIMAL(10, 2),
3767
c2 FLOAT);
3768
3769
INSERT INTO t1 VALUES (0, 1), (2, 3), (4, 5);
3770
3771
CREATE TABLE t2(
3772
c3 DECIMAL(10, 2))
3773
SELECT
3774
c1 * c2 AS c3
3775
FROM t1;
3776
3777
SELECT * FROM t1;
3778
c1	c2
3779
0.00	1
3780
2.00	3
3781
4.00	5
3782
3783
SELECT * FROM t2;
3784
c3
3785
0.00
3786
6.00
3787
20.00
3788
3789
DROP TABLE t1;
3790
DROP TABLE t2;
3791
3792
CREATE TABLE t1 (c1 BIGINT NOT NULL);
3793
INSERT INTO t1 (c1) VALUES (1);
3794
SELECT * FROM t1 WHERE c1 > NULL + 1;
3795
c1
3796
DROP TABLE t1;
3797
3798
CREATE TABLE t1 (a VARCHAR(10) NOT NULL PRIMARY KEY);
3799
INSERT INTO t1 (a) VALUES ('foo0'), ('bar0'), ('baz0');
3800
SELECT * FROM t1 WHERE a IN (CONCAT('foo', 0), 'bar');
3801
a
3802
foo0
3803
DROP TABLE t1;
3804
CREATE TABLE t1 (a INT, b INT);
3805
CREATE TABLE t2 (a INT, c INT, KEY(a));
3806
INSERT INTO t1 VALUES (1, 1), (2, 2);
3807
INSERT INTO t2 VALUES (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
3808
(2, 1), (2, 2), (2, 3), (2, 4), (2, 5),
3809
(3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
3810
(4, 1), (4, 2), (4, 3), (4, 4), (4, 5);
3811
FLUSH STATUS;
3812
SELECT DISTINCT b FROM t1 LEFT JOIN t2 USING(a) WHERE c <= 3;
3813
b
3814
1
3815
2
3816
SHOW STATUS LIKE 'Handler_read%';
3817
Variable_name	Value
201 by Brian Aker
Convert default engine to Innodb
3818
Handler_read_first	1
3819
Handler_read_key	5
1 by brian
clean slate
3820
Handler_read_next	0
3821
Handler_read_prev	0
3822
Handler_read_rnd	0
3823
Handler_read_rnd_next	6
3824
DROP TABLE t1, t2;
3825
End of 5.0 tests
3826
create table t1(a INT, KEY (a));
3827
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
3828
SELECT a FROM t1 ORDER BY a LIMIT 2;
3829
a
3830
1
3831
2
3832
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967296;
3833
a
3834
3
3835
4
3836
5
3837
SELECT a FROM t1 ORDER BY a LIMIT 2,4294967297;
3838
a
3839
3
3840
4
3841
5
3842
DROP TABLE t1;