select.result 59.8 KB
Newer Older
unknown's avatar
unknown committed
1
drop table if exists t1,t2,t3,t4;
unknown's avatar
unknown committed
2
drop table if exists t1_1,t1_2,t9_1,t9_2,t1aa,t2aa;
unknown's avatar
unknown committed
3
drop view if exists v1;
unknown's avatar
unknown committed
4 5 6 7 8 9
CREATE TABLE t1 (
Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
);
INSERT INTO t1 VALUES (9410,9412);
select period from t1;
10 11
period
9410
unknown's avatar
unknown committed
12
select * from t1;
13 14
Period	Varor_period
9410	9412
unknown's avatar
unknown committed
15
select t1.* from t1;
16 17
Period	Varor_period
9410	9412
unknown's avatar
unknown committed
18 19 20 21 22 23 24 25 26 27 28 29 30
CREATE TABLE t2 (
auto int not null auto_increment,
fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL,
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
fld3 char(30) DEFAULT '' NOT NULL,
fld4 char(35) DEFAULT '' NOT NULL,
fld5 char(35) DEFAULT '' NOT NULL,
fld6 char(4) DEFAULT '' NOT NULL,
UNIQUE fld1 (fld1),
KEY fld3 (fld3),
PRIMARY KEY (auto)
);
select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%";
31 32
fld3
imaginable
unknown's avatar
unknown committed
33
select fld3 from t2 where fld3 like "%cultivation" ;
34 35
fld3
cultivation
unknown's avatar
unknown committed
36
select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3;
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
fld3	companynr
concoct	58
druggists	58
engrossing	58
Eurydice	58
exclaimers	58
ferociousness	58
hopelessness	58
Huey	58
imaginable	58
judges	58
merging	58
ostrich	58
peering	58
Phelps	58
presumes	58
Ruth	58
sentences	58
Shylock	58
straggled	58
synergy	58
thanking	58
tying	58
unlocks	58
unknown's avatar
unknown committed
61
select fld3,companynr from t2 where companynr = 58 order by fld3;
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fld3	companynr
concoct	58
druggists	58
engrossing	58
Eurydice	58
exclaimers	58
ferociousness	58
hopelessness	58
Huey	58
imaginable	58
judges	58
merging	58
ostrich	58
peering	58
Phelps	58
presumes	58
Ruth	58
sentences	58
Shylock	58
straggled	58
synergy	58
thanking	58
tying	58
unlocks	58
unknown's avatar
unknown committed
86
select fld3 from t2 order by fld3 desc limit 10;
87 88 89 90 91 92 93 94 95 96 97
fld3
youthfulness
yelped
Wotan
workers
Witt
witchcraft
Winsett
Willy
willed
wildcats
unknown's avatar
unknown committed
98
select fld3 from t2 order by fld3 desc limit 5;
99 100 101 102 103 104
fld3
youthfulness
yelped
Wotan
workers
Witt
unknown's avatar
unknown committed
105
select fld3 from t2 order by fld3 desc limit 5,5;
106 107 108 109 110 111
fld3
witchcraft
Winsett
Willy
willed
wildcats
unknown's avatar
unknown committed
112
select t2.fld3 from t2 where fld3 = 'honeysuckle';
113 114
fld3
honeysuckle
unknown's avatar
unknown committed
115
select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_';
116 117
fld3
honeysuckle
unknown's avatar
unknown committed
118
select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_';
119 120
fld3
honeysuckle
unknown's avatar
unknown committed
121
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%';
122 123
fld3
honeysuckle
unknown's avatar
unknown committed
124
select t2.fld3 from t2 where fld3 LIKE 'h%le';
125 126
fld3
honeysuckle
unknown's avatar
unknown committed
127
select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_';
128
fld3
unknown's avatar
unknown committed
129
select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%';
130
fld3
unknown's avatar
unknown committed
131
explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
unknown's avatar
unknown committed
132
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
133
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
unknown's avatar
unknown committed
134
explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
unknown's avatar
unknown committed
135
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
136
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
unknown's avatar
unknown committed
137
explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
unknown's avatar
unknown committed
138
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
139
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
unknown's avatar
unknown committed
140
explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
unknown's avatar
unknown committed
141
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
142
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
unknown's avatar
unknown committed
143
explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
unknown's avatar
unknown committed
144
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
145
1	SIMPLE	t2	ref	fld3	fld3	30	const	1	Using where; Using index
unknown's avatar
unknown committed
146
explain select fld3 from t2 ignore index (fld3,not_used);
147
ERROR 42000: Key column 'not_used' doesn't exist in table
unknown's avatar
unknown committed
148
explain select fld3 from t2 use index (not_used);
149
ERROR 42000: Key column 'not_used' doesn't exist in table
unknown's avatar
unknown committed
150
select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
151 152 153
fld3
honeysuckle
honoring
unknown's avatar
unknown committed
154
explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
unknown's avatar
unknown committed
155
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
156
1	SIMPLE	t2	range	fld3	fld3	30	NULL	2	Using where; Using index
unknown's avatar
unknown committed
157
select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3;
158 159 160 161
fld1	fld3
148504	Colombo
068305	Colombo
000000	nondecreasing
unknown's avatar
unknown committed
162
select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes';
163 164 165 166 167 168 169
fld1	fld3
232605	appendixes
1232605	appendixes
1232606	appendixes
1232607	appendixes
1232608	appendixes
1232609	appendixes
unknown's avatar
unknown committed
170
select fld1 from t2 where fld1=250501 or fld1="250502";
171 172 173
fld1
250501
250502
unknown's avatar
unknown committed
174
explain select fld1 from t2 where fld1=250501 or fld1="250502";
unknown's avatar
unknown committed
175
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
176
1	SIMPLE	t2	range	fld1	fld1	4	NULL	2	Using where; Using index
unknown's avatar
unknown committed
177
select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
178 179 180 181 182
fld1
250501
250502
250505
250601
unknown's avatar
unknown committed
183
explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
unknown's avatar
unknown committed
184
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
185
1	SIMPLE	t2	range	fld1	fld1	4	NULL	4	Using where; Using index
unknown's avatar
unknown committed
186
select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%';
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
fld1	fld3
218401	faithful
018007	fanatic
228311	fated
018017	featherweight
218022	feed
088303	feminine
058004	Fenton
038017	fetched
018054	fetters
208101	fiftieth
238007	filial
013606	fingerings
218008	finishers
038205	firearm
188505	fitting
202301	Fitzpatrick
238008	fixedly
012001	flanking
018103	flint
018104	flopping
188007	flurried
013602	foldout
226205	foothill
232102	forgivably
228306	forthcoming
186002	freakish
208113	freest
231315	freezes
036002	funereal
226209	furnishings
198006	furthermore
unknown's avatar
unknown committed
219
select fld3 from t2 where fld3 like "L%" and fld3 = "ok";
220
fld3
unknown's avatar
unknown committed
221
select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly");
222 223
fld3
Chantilly
unknown's avatar
unknown committed
224
select fld1,fld3 from t2 where fld1 like "25050%";
225 226 227 228 229 230
fld1	fld3
250501	poisoning
250502	Iraqis
250503	heaving
250504	population
250505	bomb
unknown's avatar
unknown committed
231
select fld1,fld3 from t2 where fld1 like "25050_";
232 233 234 235 236 237
fld1	fld3
250501	poisoning
250502	Iraqis
250503	heaving
250504	population
250505	bomb
unknown's avatar
unknown committed
238
select distinct companynr from t2;
239 240 241 242 243 244 245 246 247 248 249 250 251
companynr
00
37
36
50
58
29
40
53
65
41
34
68
unknown's avatar
unknown committed
252
select distinct companynr from t2 order by companynr;
253 254 255 256 257 258 259 260 261 262 263 264 265
companynr
00
29
34
36
37
40
41
50
53
58
65
68
unknown's avatar
unknown committed
266
select distinct companynr from t2 order by companynr desc;
267 268 269 270 271 272 273 274 275 276 277 278 279
companynr
68
65
58
53
50
41
40
37
36
34
29
00
unknown's avatar
unknown committed
280
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
281 282 283 284 285 286 287
fld3	period
obliterates	9410
offload	9410
opaquely	9410
organizer	9410
overestimating	9410
overlay	9410
unknown's avatar
unknown committed
288
select distinct fld3 from t2 where companynr = 34 order by fld3;
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
fld3
absentee
accessed
ahead
alphabetic
Asiaticizations
attitude
aye
bankruptcies
belays
Blythe
bomb
boulevard
bulldozes
cannot
caressing
charcoal
checksumming
chess
clubroom
colorful
cosy
creator
crying
Darius
diffusing
duality
Eiffel
Epiphany
Ernestine
explorers
exterminated
famine
forked
Gershwins
heaving
Hodges
Iraqis
Italianization
Lagos
landslide
libretto
Majorca
mastering
narrowed
occurred
offerers
Palestine
Peruvianizes
pharmaceutic
poisoning
population
Pygmalion
rats
realest
recording
regimented
retransmitting
reviver
rouses
scars
sicker
sleepwalk
stopped
sugars
translatable
uncles
unexpected
uprisings
versatility
vest
unknown's avatar
unknown committed
360
select distinct fld3 from t2 limit 10;
361 362 363 364 365 366 367 368 369 370 371
fld3
abates
abiding
Abraham
abrogating
absentee
abut
accessed
accruing
accumulating
accuracies
unknown's avatar
unknown committed
372
select distinct fld3 from t2 having fld3 like "A%" limit 10;
373 374 375 376 377 378 379 380 381 382 383
fld3
abates
abiding
Abraham
abrogating
absentee
abut
accessed
accruing
accumulating
accuracies
unknown's avatar
unknown committed
384
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
substring(fld3,1,3)
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
Adl
adm
Ado
ads
adv
aer
aff
afi
afl
afo
agi
ahe
aim
air
Ald
alg
ali
all
alp
alr
ama
ame
amm
ana
and
ane
Ang
ani
Ann
Ant
api
app
aqu
Ara
arc
Arm
arr
Art
Asi
ask
asp
ass
ast
att
aud
Aug
aut
ave
avo
awe
aye
Azt
unknown's avatar
unknown committed
448
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
449 450 451 452 453 454 455 456 457 458 459
a
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
unknown's avatar
unknown committed
460
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
461 462 463 464 465 466 467 468 469 470 471
substring(fld3,1,3)
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
unknown's avatar
unknown committed
472
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
473 474 475 476 477 478 479 480 481 482 483
a
aba
abi
Abr
abs
abu
acc
acq
acu
Ade
adj
unknown's avatar
unknown committed
484 485 486 487 488 489 490 491 492
create table t3 (
period    int not null,
name      char(32) not null,
companynr int not null,
price     double(11,0),
price2     double(11,0),
key (period),
key (name)
);
unknown's avatar
unknown committed
493
create temporary table tmp engine = myisam select * from t3;
unknown's avatar
unknown committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
insert into tmp select * from t3;
insert into t3 select * from tmp;
alter table t3 add t2nr int not null auto_increment primary key first;
drop table tmp;
unknown's avatar
unknown committed
513
SET SQL_BIG_TABLES=1;
unknown's avatar
unknown committed
514
select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10;
515 516 517 518 519 520 521 522 523 524 525
namn
Abraham Abraham
abrogating abrogating
admonishing admonishing
Adolph Adolph
afield afield
aging aging
ammonium ammonium
analyzable analyzable
animals animals
animized animized
unknown's avatar
unknown committed
526
SET SQL_BIG_TABLES=0;
unknown's avatar
unknown committed
527
select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10;
528 529 530 531 532 533 534 535 536 537 538
concat(fld3," ",fld3)
Abraham Abraham
abrogating abrogating
admonishing admonishing
Adolph Adolph
afield afield
aging aging
ammonium ammonium
analyzable analyzable
animals animals
animized animized
unknown's avatar
unknown committed
539
select distinct fld5 from t2 limit 10;
540 541 542 543 544 545 546 547 548 549 550
fld5
neat
Steinberg
jarring
tinily
balled
persist
attainments
fanatic
measures
rightfulness
unknown's avatar
unknown committed
551
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
552 553 554 555 556 557 558 559 560 561 562
fld3	count(*)
affixed	1
and	1
annoyers	1
Anthony	1
assayed	1
assurers	1
attendants	1
bedlam	1
bedpost	1
boasted	1
unknown's avatar
unknown committed
563
SET SQL_BIG_TABLES=1;
unknown's avatar
unknown committed
564
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
565 566 567 568 569 570 571 572 573 574 575
fld3	count(*)
affixed	1
and	1
annoyers	1
Anthony	1
assayed	1
assurers	1
attendants	1
bedlam	1
bedpost	1
boasted	1
unknown's avatar
unknown committed
576
SET SQL_BIG_TABLES=0;
unknown's avatar
unknown committed
577
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
578 579 580 581 582 583 584 585 586 587 588
fld3	repeat("a",length(fld3))	count(*)
circus	aaaaaa	1
cited	aaaaa	1
Colombo	aaaaaaa	1
congresswoman	aaaaaaaaaaaaa	1
contrition	aaaaaaaaaa	1
corny	aaaaa	1
cultivation	aaaaaaaaaaa	1
definiteness	aaaaaaaaaaaa	1
demultiplex	aaaaaaaaaaa	1
disappointing	aaaaaaaaaaaaa	1
unknown's avatar
unknown committed
589
select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2;
590 591 592 593 594 595 596 597
companynr	rtrim(space(512+companynr))
37	
78	
101	
154	
311	
447	
512	
unknown's avatar
unknown committed
598
select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3;
599
fld3
unknown's avatar
unknown committed
600
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
unknown's avatar
unknown committed
601
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
602
1	SIMPLE	t2	ALL	fld1	NULL	NULL	NULL	1199	Using where; Using temporary; Using filesort
603
1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.fld1	1	Using where; Using index
unknown's avatar
unknown committed
604
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
unknown's avatar
unknown committed
605 606
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	period	NULL	NULL	NULL	41810	Using temporary; Using filesort
607
1	SIMPLE	t3	ref	period	period	4	test.t1.period	4181	
unknown's avatar
unknown committed
608
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
unknown's avatar
unknown committed
609 610
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	index	period	period	4	NULL	41810	
611
1	SIMPLE	t1	ref	period	period	4	test.t3.period	4181	
unknown's avatar
unknown committed
612
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
unknown's avatar
unknown committed
613 614
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	period	period	4	NULL	41810	
615
1	SIMPLE	t3	ref	period	period	4	test.t1.period	4181	
unknown's avatar
unknown committed
616
select period from t1;
617 618
period
9410
unknown's avatar
unknown committed
619
select period from t1 where period=1900;
620
period
unknown's avatar
unknown committed
621
select fld3,period from t1,t2 where fld1 = 011401 order by period;
622 623
fld3	period
breaking	9410
unknown's avatar
unknown committed
624
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
625 626
fld3	period
breaking	1001
unknown's avatar
unknown committed
627
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
unknown's avatar
unknown committed
628
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
629 630
1	SIMPLE	t2	const	fld1	fld1	4	const	1	
1	SIMPLE	t3	const	PRIMARY,period	PRIMARY	4	const	1	
unknown's avatar
unknown committed
631
select fld3,period from t2,t1 where companynr*10 = 37*10;
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
fld3	period
breaking	9410
Romans	9410
intercepted	9410
bewilderingly	9410
astound	9410
admonishing	9410
sumac	9410
flanking	9410
combed	9410
subjective	9410
scatterbrain	9410
Eulerian	9410
Kane	9410
overlay	9410
perturb	9410
goblins	9410
annihilates	9410
Wotan	9410
snatching	9410
concludes	9410
laterally	9410
yelped	9410
grazing	9410
Baird	9410
celery	9410
misunderstander	9410
handgun	9410
foldout	9410
mystic	9410
succumbed	9410
Nabisco	9410
fingerings	9410
aging	9410
afield	9410
ammonium	9410
boat	9410
intelligibility	9410
Augustine	9410
teethe	9410
dreaded	9410
scholastics	9410
audiology	9410
wallet	9410
parters	9410
eschew	9410
quitter	9410
neat	9410
Steinberg	9410
jarring	9410
tinily	9410
balled	9410
persist	9410
attainments	9410
fanatic	9410
measures	9410
rightfulness	9410
capably	9410
impulsive	9410
starlet	9410
terminators	9410
untying	9410
announces	9410
featherweight	9410
pessimist	9410
daughter	9410
decliner	9410
lawgiver	9410
stated	9410
readable	9410
attrition	9410
cascade	9410
motors	9410
interrogate	9410
pests	9410
stairway	9410
dopers	9410
testicle	9410
Parsifal	9410
leavings	9410
postulation	9410
squeaking	9410
contrasted	9410
leftover	9410
whiteners	9410
erases	9410
Punjab	9410
Merritt	9410
Quixotism	9410
sweetish	9410
dogging	9410
scornfully	9410
bellow	9410
bills	9410
cupboard	9410
sureties	9410
puddings	9410
fetters	9410
bivalves	9410
incurring	9410
Adolph	9410
pithed	9410
Miles	9410
trimmings	9410
tragedies	9410
skulking	9410
flint	9410
flopping	9410
relaxing	9410
offload	9410
suites	9410
lists	9410
animized	9410
multilayer	9410
standardizes	9410
Judas	9410
vacuuming	9410
dentally	9410
humanness	9410
inch	9410
Weissmuller	9410
irresponsibly	9410
luckily	9410
culled	9410
medical	9410
bloodbath	9410
subschema	9410
animals	9410
Micronesia	9410
repetitions	9410
Antares	9410
ventilate	9410
pityingly	9410
interdependent	9410
Graves	9410
neonatal	9410
chafe	9410
honoring	9410
realtor	9410
elite	9410
funereal	9410
abrogating	9410
sorters	9410
Conley	9410
lectured	9410
Abraham	9410
Hawaii	9410
cage	9410
hushes	9410
Simla	9410
reporters	9410
Dutchman	9410
descendants	9410
groupings	9410
dissociate	9410
coexist	9410
Beebe	9410
Taoism	9410
Connally	9410
fetched	9410
checkpoints	9410
rusting	9410
galling	9410
obliterates	9410
traitor	9410
resumes	9410
analyzable	9410
terminator	9410
gritty	9410
firearm	9410
minima	9410
Selfridge	9410
disable	9410
witchcraft	9410
betroth	9410
Manhattanize	9410
imprint	9410
peeked	9410
swelling	9410
interrelationships	9410
riser	9410
Gandhian	9410
peacock	9410
bee	9410
kanji	9410
dental	9410
scarf	9410
chasm	9410
insolence	9410
syndicate	9410
alike	9410
imperial	9410
convulsion	9410
railway	9410
validate	9410
normalizes	9410
comprehensive	9410
chewing	9410
denizen	9410
schemer	9410
chronicle	9410
Kline	9410
Anatole	9410
partridges	9410
brunch	9410
recruited	9410
dimensions	9410
Chicana	9410
announced	9410
praised	9410
employing	9410
linear	9410
quagmire	9410
western	9410
relishing	9410
serving	9410
scheduling	9410
lore	9410
eventful	9410
arteriole	9410
disentangle	9410
cured	9410
Fenton	9410
avoidable	9410
drains	9410
detectably	9410
husky	9410
impelling	9410
undoes	9410
evened	9410
squeezes	9410
destroyer	9410
rudeness	9410
beaner	9410
boorish	9410
Everhart	9410
encompass	9410
mushrooms	9410
Alison	9410
externally	9410
pellagra	9410
cult	9410
creek	9410
Huffman	9410
Majorca	9410
governing	9410
gadfly	9410
reassigned	9410
intentness	9410
craziness	9410
psychic	9410
squabbled	9410
burlesque	9410
capped	9410
extracted	9410
DiMaggio	9410
exclamation	9410
subdirectory	9410
Gothicism	9410
feminine	9410
metaphysically	9410
sanding	9410
Miltonism	9410
freakish	9410
index	9410
straight	9410
flurried	9410
denotative	9410
coming	9410
commencements	9410
gentleman	9410
gifted	9410
Shanghais	9410
sportswriting	9410
sloping	9410
navies	9410
leaflet	9410
shooter	9410
Joplin	9410
babies	9410
assails	9410
admiring	9410
swaying	9410
Goldstine	9410
fitting	9410
Norwalk	9410
analogy	9410
deludes	9410
cokes	9410
Clayton	9410
exhausts	9410
causality	9410
sating	9410
icon	9410
throttles	9410
communicants	9410
dehydrate	9410
priceless	9410
publicly	9410
incidentals	9410
commonplace	9410
mumbles	9410
furthermore	9410
cautioned	9410
parametrized	9410
registration	9410
sadly	9410
positioning	9410
babysitting	9410
eternal	9410
hoarder	9410
congregates	9410
rains	9410
workers	9410
sags	9410
unplug	9410
garage	9410
boulder	9410
specifics	9410
Teresa	9410
Winsett	9410
convenient	9410
buckboards	9410
amenities	9410
resplendent	9410
sews	9410
participated	9410
Simon	9410
certificates	9410
Fitzpatrick	9410
Evanston	9410
misted	9410
textures	9410
save	9410
count	9410
rightful	9410
chaperone	9410
Lizzy	9410
clenched	9410
effortlessly	9410
accessed	9410
beaters	9410
Hornblower	9410
vests	9410
indulgences	9410
infallibly	9410
unwilling	9410
excrete	9410
spools	9410
crunches	9410
overestimating	9410
ineffective	9410
humiliation	9410
sophomore	9410
star	9410
rifles	9410
dialysis	9410
arriving	9410
indulge	9410
clockers	9410
languages	9410
Antarctica	9410
percentage	9410
ceiling	9410
specification	9410
regimented	9410
ciphers	9410
pictures	9410
serpents	9410
allot	9410
realized	9410
mayoral	9410
opaquely	9410
hostess	9410
fiftieth	9410
incorrectly	9410
decomposition	9410
stranglings	9410
mixture	9410
electroencephalography	9410
similarities	9410
charges	9410
freest	9410
Greenberg	9410
tinting	9410
expelled	9410
warm	9410
smoothed	9410
deductions	9410
Romano	9410
bitterroot	9410
corset	9410
securing	9410
environing	9410
cute	9410
Crays	9410
heiress	9410
inform	9410
avenge	9410
universals	9410
Kinsey	9410
ravines	9410
bestseller	9410
equilibrium	9410
extents	9410
relatively	9410
pressure	9410
critiques	9410
befouled	9410
rightfully	9410
mechanizing	9410
Latinizes	9410
timesharing	9410
Aden	9410
embassies	9410
males	9410
shapelessly	9410
mastering	9410
Newtonian	9410
finishers	9410
abates	9410
teem	9410
kiting	9410
stodgy	9410
feed	9410
guitars	9410
airships	9410
store	9410
denounces	9410
Pyle	9410
Saxony	9410
serializations	9410
Peruvian	9410
taxonomically	9410
kingdom	9410
stint	9410
Sault	9410
faithful	9410
Ganymede	9410
tidiness	9410
gainful	9410
contrary	9410
Tipperary	9410
tropics	9410
theorizers	9410
renew	9410
already	9410
terminal	9410
Hegelian	9410
hypothesizer	9410
warningly	9410
journalizing	9410
nested	9410
Lars	9410
saplings	9410
foothill	9410
labeled	9410
imperiously	9410
reporters	9410
furnishings	9410
precipitable	9410
discounts	9410
excises	9410
Stalin	9410
despot	9410
ripeness	9410
Arabia	9410
unruly	9410
mournfulness	9410
boom	9410
slaughter	9410
Sabine	9410
handy	9410
rural	9410
organizer	9410
shipyard	9410
civics	9410
inaccuracy	9410
rules	9410
juveniles	9410
comprised	9410
investigations	9410
stabilizes	9410
seminaries	9410
Hunter	9410
sporty	9410
test	9410
weasels	9410
CERN	9410
tempering	9410
afore	9410
Galatean	9410
techniques	9410
error	9410
veranda	9410
severely	9410
Cassites	9410
forthcoming	9410
guides	9410
vanish	9410
lied	9410
sawtooth	9410
fated	9410
gradually	9410
widens	9410
preclude	9410
evenhandedly	9410
percentage	9410
disobedience	9410
humility	9410
gleaning	9410
petted	9410
bloater	9410
minion	9410
marginal	9410
apiary	9410
measures	9410
precaution	9410
repelled	9410
primary	9410
coverings	9410
Artemia	9410
navigate	9410
spatial	9410
Gurkha	9410
meanwhile	9410
Melinda	9410
Butterfield	9410
Aldrich	9410
previewing	9410
glut	9410
unaffected	9410
inmate	9410
mineral	9410
impending	9410
meditation	9410
ideas	9410
miniaturizes	9410
lewdly	9410
title	9410
youthfulness	9410
creak	9410
Chippewa	9410
clamored	9410
freezes	9410
forgivably	9410
reduce	9410
McGovern	9410
Nazis	9410
epistle	9410
socializes	9410
conceptions	9410
Kevin	9410
uncovering	9410
chews	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
appendixes	9410
raining	9410
infest	9410
compartment	9410
minting	9410
ducks	9410
roped	9410
waltz	9410
Lillian	9410
repressions	9410
chillingly	9410
noncritical	9410
lithograph	9410
spongers	9410
parenthood	9410
posed	9410
instruments	9410
filial	9410
fixedly	9410
relives	9410
Pandora	9410
watering	9410
ungrateful	9410
secures	9410
poison	9410
dusted	9410
encompasses	9410
presentation	9410
Kantian	9410
unknown's avatar
unknown committed
1221
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;
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
fld3	period	price	price2
admonishing	1002	28357832	8723648
analyzable	1002	28357832	8723648
annihilates	1001	5987435	234724
Antares	1002	28357832	8723648
astound	1001	5987435	234724
audiology	1001	5987435	234724
Augustine	1002	28357832	8723648
Baird	1002	28357832	8723648
bewilderingly	1001	5987435	234724
breaking	1001	5987435	234724
Conley	1001	5987435	234724
dentally	1002	28357832	8723648
dissociate	1002	28357832	8723648
elite	1001	5987435	234724
eschew	1001	5987435	234724
Eulerian	1001	5987435	234724
flanking	1001	5987435	234724
foldout	1002	28357832	8723648
funereal	1002	28357832	8723648
galling	1002	28357832	8723648
Graves	1001	5987435	234724
grazing	1001	5987435	234724
groupings	1001	5987435	234724
handgun	1001	5987435	234724
humility	1002	28357832	8723648
impulsive	1002	28357832	8723648
inch	1001	5987435	234724
intelligibility	1001	5987435	234724
jarring	1001	5987435	234724
lawgiver	1001	5987435	234724
lectured	1002	28357832	8723648
Merritt	1002	28357832	8723648
neonatal	1001	5987435	234724
offload	1002	28357832	8723648
parters	1002	28357832	8723648
pityingly	1002	28357832	8723648
puddings	1002	28357832	8723648
Punjab	1001	5987435	234724
quitter	1002	28357832	8723648
realtor	1001	5987435	234724
relaxing	1001	5987435	234724
repetitions	1001	5987435	234724
resumes	1001	5987435	234724
Romans	1002	28357832	8723648
rusting	1001	5987435	234724
scholastics	1001	5987435	234724
skulking	1002	28357832	8723648
stated	1002	28357832	8723648
suites	1002	28357832	8723648
sureties	1001	5987435	234724
testicle	1002	28357832	8723648
tinily	1002	28357832	8723648
tragedies	1001	5987435	234724
trimmings	1001	5987435	234724
vacuuming	1001	5987435	234724
ventilate	1001	5987435	234724
wallet	1001	5987435	234724
Weissmuller	1002	28357832	8723648
Wotan	1002	28357832	8723648
unknown's avatar
unknown committed
1282
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;
1283 1284 1285 1286 1287
fld1	fld3	period	price	price2
018201	relaxing	1001	5987435	234724
018601	vacuuming	1001	5987435	234724
018801	inch	1001	5987435	234724
018811	repetitions	1001	5987435	234724
unknown's avatar
unknown committed
1288 1289 1290 1291 1292
create table t4 (
companynr tinyint(2) unsigned zerofill NOT NULL default '00',
companyname char(30) NOT NULL default '',
PRIMARY KEY (companynr),
UNIQUE KEY companyname(companyname)
unknown's avatar
unknown committed
1293
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
unknown's avatar
unknown committed
1294
select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
companynr	companyname
00	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
unknown's avatar
unknown committed
1308
select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr;
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
companynr	companyname
00	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
unknown's avatar
unknown committed
1322
select * from t1,t1 t12;
1323 1324
Period	Varor_period	Period	Varor_period
9410	9412	9410	9412
unknown's avatar
unknown committed
1325
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;
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
fld1	fld1
250501	250501
250502	250501
250503	250501
250504	250501
250505	250501
250501	250502
250502	250502
250503	250502
250504	250502
250505	250502
250501	250503
250502	250503
250503	250503
250504	250503
250505	250503
250501	250504
250502	250504
250503	250504
250504	250504
250505	250504
250501	250505
250502	250505
250503	250505
250504	250505
250505	250505
1352
insert into t2 (fld1, companynr) values (999999,99);
unknown's avatar
unknown committed
1353
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1354
companynr	companyname
1355 1356 1357 1358
99	NULL
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
count(*)
1199
unknown's avatar
unknown committed
1359
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
unknown's avatar
unknown committed
1360
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1361
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1200	
unknown's avatar
unknown committed
1362
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	Using where; Not exists
unknown's avatar
unknown committed
1363
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
unknown's avatar
unknown committed
1364
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1365
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
unknown's avatar
unknown committed
1366
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1200	Using where; Not exists
1367 1368
delete from t2 where fld1=999999;
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
unknown's avatar
unknown committed
1369 1370 1371
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
1372
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
unknown's avatar
unknown committed
1373 1374 1375
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
1376
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
unknown's avatar
unknown committed
1377 1378
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1379
1	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	1	test.t2.companynr	1	
1380
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
unknown's avatar
unknown committed
1381 1382 1383
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1384
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
unknown's avatar
unknown committed
1385 1386 1387
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	PRIMARY	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
1388
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
unknown's avatar
unknown committed
1389 1390 1391 1392 1393 1394 1395 1396
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
companynr	companynr
37	36
41	40
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
unknown's avatar
unknown committed
1397
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1398 1399
1	SIMPLE	t4	index	NULL	PRIMARY	1	NULL	12	Using index; Using temporary
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
unknown's avatar
unknown committed
1400
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;
1401 1402 1403
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
unknown's avatar
unknown committed
1404
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;
1405 1406 1407
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
unknown's avatar
unknown committed
1408
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;
1409 1410 1411
fld1	companynr	fld3	period
038008	37	reporters	1008
038208	37	Selfridge	1008
unknown's avatar
unknown committed
1412
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);
1413 1414
period
9410
unknown's avatar
unknown committed
1415
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)));
1416 1417
period
9410
unknown's avatar
unknown committed
1418
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;
1419 1420 1421 1422 1423
fld1
250501
250502
250503
250505
unknown's avatar
unknown committed
1424
select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606);
1425 1426 1427
fld1
250502
250503
unknown's avatar
unknown committed
1428
select fld1 from t2 where fld1 between 250502 and 250504;
1429 1430 1431 1432
fld1
250502
250503
250504
unknown's avatar
unknown committed
1433
select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ;
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
fld3
label
labeled
labeled
landslide
laterally
leaflet
lewdly
Lillian
luckily
unknown's avatar
unknown committed
1444
select count(*) from t1;
1445 1446
count(*)
1
unknown's avatar
unknown committed
1447
select companynr,count(*),sum(fld1) from t2 group by companynr;
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460
companynr	count(*)	sum(fld1)
00	82	10355753
29	95	14473298
34	70	17788966
36	215	22786296
37	588	83602098
40	37	6618386
41	52	12816335
50	11	1595438
53	4	793210
58	23	2254293
65	10	2284055
68	12	3097288
unknown's avatar
unknown committed
1461
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1462 1463 1464 1465 1466 1467
companynr	count(*)
68	12
65	10
58	23
53	4
50	11
unknown's avatar
unknown committed
1468 1469 1470
select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
1471 1472 1473 1474
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
Warnings:
1475
Note	1003	select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld4` <> _latin1''))
unknown's avatar
unknown committed
1476 1477 1478 1479 1480
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
companynr	count(*)	min(fld4)	max(fld4)	sum(fld1)	avg(fld1)	std(fld1)	variance(fld1)
00	82	Anthony	windmills	10355753	126289.6707	115550.9757	13352027981.7087
29	95	abut	wetness	14473298	152350.5053	8368.5480	70032594.9026
34	70	absentee	vest	17788966	254128.0857	3272.5940	10709871.3069
unknown's avatar
unknown committed
1481
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	1	1	5987435	5987435	5987435	5987435.0000
37	2	1	28357832	28357832	28357832	28357832.0000
37	3	1	39654943	39654943	39654943	39654943.0000
37	11	1	5987435	5987435	5987435	5987435.0000
37	12	1	28357832	28357832	28357832	28357832.0000
37	13	1	39654943	39654943	39654943	39654943.0000
37	21	1	5987435	5987435	5987435	5987435.0000
37	22	1	28357832	28357832	28357832	28357832.0000
37	23	1	39654943	39654943	39654943	39654943.0000
37	31	1	5987435	5987435	5987435	5987435.0000
unknown's avatar
unknown committed
1493
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;
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
companynr	t2nr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	1	1	5987435	5987435	5987435	5987435.0000
37	2	1	28357832	28357832	28357832	28357832.0000
37	3	1	39654943	39654943	39654943	39654943.0000
37	11	1	5987435	5987435	5987435	5987435.0000
37	12	1	28357832	28357832	28357832	28357832.0000
37	13	1	39654943	39654943	39654943	39654943.0000
37	21	1	5987435	5987435	5987435	5987435.0000
37	22	1	28357832	28357832	28357832	28357832.0000
37	23	1	39654943	39654943	39654943	39654943.0000
37	31	1	5987435	5987435	5987435	5987435.0000
unknown's avatar
unknown committed
1505
select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ;
1506 1507 1508 1509 1510 1511 1512 1513
companynr	count(price)	sum(price)	min(price)	max(price)	avg(price)
37	12543	309394878010	5987435	39654943	24666736.6667
78	8362	414611089292	726498	98439034	49582766.0000
101	4181	3489454238	834598	834598	834598.0000
154	4181	4112197254950	983543950	983543950	983543950.0000
311	4181	979599938	234298	234298	234298.0000
447	4181	9929180954	2374834	2374834	2374834.0000
512	4181	3288532102	786542	786542	786542.0000
unknown's avatar
unknown committed
1514
select distinct mod(companynr,10) from t4 group by companynr;
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
mod(companynr,10)
0
9
4
6
7
1
3
8
5
unknown's avatar
unknown committed
1525
select distinct 1 from t4 group by companynr;
1526 1527
1
1
unknown's avatar
unknown committed
1528
select count(distinct fld1) from t2;
1529 1530
count(distinct fld1)
1199
unknown's avatar
unknown committed
1531
select companynr,count(distinct fld1) from t2 group by companynr;
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544
companynr	count(distinct fld1)
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
unknown's avatar
unknown committed
1545
select companynr,count(*) from t2 group by companynr;
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
companynr	count(*)
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
unknown's avatar
unknown committed
1559
select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr;
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
companynr	count(distinct concat(fld1,repeat(65,1000)))
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
unknown's avatar
unknown committed
1573
select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr;
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586
companynr	count(distinct concat(fld1,repeat(65,200)))
00	82
29	95
34	70
36	215
37	588
40	37
41	52
50	11
53	4
58	23
65	10
68	12
unknown's avatar
unknown committed
1587
select companynr,count(distinct floor(fld1/100)) from t2 group by companynr;
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
companynr	count(distinct floor(fld1/100))
00	47
29	35
34	14
36	69
37	108
40	16
41	11
50	9
53	1
58	1
65	1
68	1
unknown's avatar
unknown committed
1601
select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr;
1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614
companynr	count(distinct concat(repeat(65,1000),floor(fld1/100)))
00	47
29	35
34	14
36	69
37	108
40	16
41	11
50	9
53	1
58	1
65	1
68	1
unknown's avatar
unknown committed
1615
select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10;
1616 1617
sum(fld1)	fld3
11402	Romans
unknown's avatar
unknown committed
1618
select name,count(*) from t3 where name='cloakroom' group by name;
1619 1620
name	count(*)
cloakroom	4181
unknown's avatar
unknown committed
1621
select name,count(*) from t3 where name='cloakroom' and price>10 group by name;
1622 1623
name	count(*)
cloakroom	4181
unknown's avatar
unknown committed
1624
select count(*) from t3 where name='cloakroom' and price2=823742;
1625 1626
count(*)
4181
unknown's avatar
unknown committed
1627
select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name;
1628 1629
name	count(*)
cloakroom	4181
unknown's avatar
unknown committed
1630
select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name;
1631 1632 1633 1634 1635 1636 1637 1638
name	count(*)
extramarital	4181
gazer	4181
gems	4181
Iranizes	4181
spates	4181
tucked	4181
violinist	4181
unknown's avatar
unknown committed
1639
select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1640 1641
fld3	count(*)
spates	4181
unknown's avatar
unknown committed
1642
select companynr|0,companyname from t4 group by 1;
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655
companynr|0	companyname
0	Unknown
29	company 1
34	company 2
36	company 3
37	company 4
40	company 5
41	company 6
50	company 11
53	company 7
58	company 8
65	company 9
68	company 10
unknown's avatar
unknown committed
1656
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname;
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
companynr	companyname	count(*)
29	company 1	95
68	company 10	12
50	company 11	11
34	company 2	70
36	company 3	215
37	company 4	588
40	company 5	37
41	company 6	52
53	company 7	4
58	company 8	23
65	company 9	10
00	Unknown	82
unknown's avatar
unknown committed
1670
select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1671 1672
fld1	count(*)
158402	4181
unknown's avatar
unknown committed
1673
select sum(Period)/count(*) from t1;
1674
sum(Period)/count(*)
unknown's avatar
unknown committed
1675
9410.00000
unknown's avatar
unknown committed
1676
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;
1677 1678 1679 1680 1681 1682 1683 1684
companynr	count	sum	diff	func
37	12543	309394878010	0.0000	464091
78	8362	414611089292	0.0000	652236
101	4181	3489454238	0.0000	422281
154	4181	4112197254950	0.0000	643874
311	4181	979599938	0.0000	1300291
447	4181	9929180954	0.0000	1868907
512	4181	3288532102	0.0000	2140672
unknown's avatar
unknown committed
1685
select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg;
1686 1687
companynr	avg
154	983543950.00
unknown's avatar
unknown committed
1688
select companynr,count(*) from t2 group by companynr order by 2 desc;
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701
companynr	count(*)
37	588
36	215
29	95
00	82
34	70
41	52
40	37
58	23
68	12
50	11
65	10
53	4
unknown's avatar
unknown committed
1702
select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc;
1703 1704 1705 1706 1707 1708 1709
companynr	count(*)
41	52
58	23
68	12
50	11
65	10
53	4
unknown's avatar
unknown committed
1710
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;
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798
fld4	fld1	count(price)	sum(price)	min(price)	max(price)	avg(price)
teethe	000001	1	5987435	5987435	5987435	5987435.0000
dreaded	011401	1	5987435	5987435	5987435	5987435.0000
scholastics	011402	1	28357832	28357832	28357832	28357832.0000
audiology	011403	1	39654943	39654943	39654943	39654943.0000
wallet	011501	1	5987435	5987435	5987435	5987435.0000
parters	011701	1	5987435	5987435	5987435	5987435.0000
eschew	011702	1	28357832	28357832	28357832	28357832.0000
quitter	011703	1	39654943	39654943	39654943	39654943.0000
neat	012001	1	5987435	5987435	5987435	5987435.0000
Steinberg	012003	1	39654943	39654943	39654943	39654943.0000
balled	012301	1	5987435	5987435	5987435	5987435.0000
persist	012302	1	28357832	28357832	28357832	28357832.0000
attainments	012303	1	39654943	39654943	39654943	39654943.0000
capably	012501	1	5987435	5987435	5987435	5987435.0000
impulsive	012602	1	28357832	28357832	28357832	28357832.0000
starlet	012603	1	39654943	39654943	39654943	39654943.0000
featherweight	012701	1	5987435	5987435	5987435	5987435.0000
pessimist	012702	1	28357832	28357832	28357832	28357832.0000
daughter	012703	1	39654943	39654943	39654943	39654943.0000
lawgiver	013601	1	5987435	5987435	5987435	5987435.0000
stated	013602	1	28357832	28357832	28357832	28357832.0000
readable	013603	1	39654943	39654943	39654943	39654943.0000
testicle	013801	1	5987435	5987435	5987435	5987435.0000
Parsifal	013802	1	28357832	28357832	28357832	28357832.0000
leavings	013803	1	39654943	39654943	39654943	39654943.0000
squeaking	013901	1	5987435	5987435	5987435	5987435.0000
contrasted	016001	1	5987435	5987435	5987435	5987435.0000
leftover	016201	1	5987435	5987435	5987435	5987435.0000
whiteners	016202	1	28357832	28357832	28357832	28357832.0000
erases	016301	1	5987435	5987435	5987435	5987435.0000
Punjab	016302	1	28357832	28357832	28357832	28357832.0000
Merritt	016303	1	39654943	39654943	39654943	39654943.0000
sweetish	018001	1	5987435	5987435	5987435	5987435.0000
dogging	018002	1	28357832	28357832	28357832	28357832.0000
scornfully	018003	1	39654943	39654943	39654943	39654943.0000
fetters	018012	1	28357832	28357832	28357832	28357832.0000
bivalves	018013	1	39654943	39654943	39654943	39654943.0000
skulking	018021	1	5987435	5987435	5987435	5987435.0000
flint	018022	1	28357832	28357832	28357832	28357832.0000
flopping	018023	1	39654943	39654943	39654943	39654943.0000
Judas	018032	1	28357832	28357832	28357832	28357832.0000
vacuuming	018033	1	39654943	39654943	39654943	39654943.0000
medical	018041	1	5987435	5987435	5987435	5987435.0000
bloodbath	018042	1	28357832	28357832	28357832	28357832.0000
subschema	018043	1	39654943	39654943	39654943	39654943.0000
interdependent	018051	1	5987435	5987435	5987435	5987435.0000
Graves	018052	1	28357832	28357832	28357832	28357832.0000
neonatal	018053	1	39654943	39654943	39654943	39654943.0000
sorters	018061	1	5987435	5987435	5987435	5987435.0000
epistle	018062	1	28357832	28357832	28357832	28357832.0000
Conley	018101	1	5987435	5987435	5987435	5987435.0000
lectured	018102	1	28357832	28357832	28357832	28357832.0000
Abraham	018103	1	39654943	39654943	39654943	39654943.0000
cage	018201	1	5987435	5987435	5987435	5987435.0000
hushes	018202	1	28357832	28357832	28357832	28357832.0000
Simla	018402	1	28357832	28357832	28357832	28357832.0000
reporters	018403	1	39654943	39654943	39654943	39654943.0000
coexist	018601	1	5987435	5987435	5987435	5987435.0000
Beebe	018602	1	28357832	28357832	28357832	28357832.0000
Taoism	018603	1	39654943	39654943	39654943	39654943.0000
Connally	018801	1	5987435	5987435	5987435	5987435.0000
fetched	018802	1	28357832	28357832	28357832	28357832.0000
checkpoints	018803	1	39654943	39654943	39654943	39654943.0000
gritty	018811	1	5987435	5987435	5987435	5987435.0000
firearm	018812	1	28357832	28357832	28357832	28357832.0000
minima	019101	1	5987435	5987435	5987435	5987435.0000
Selfridge	019102	1	28357832	28357832	28357832	28357832.0000
disable	019103	1	39654943	39654943	39654943	39654943.0000
witchcraft	019201	1	5987435	5987435	5987435	5987435.0000
betroth	030501	1	5987435	5987435	5987435	5987435.0000
Manhattanize	030502	1	28357832	28357832	28357832	28357832.0000
imprint	030503	1	39654943	39654943	39654943	39654943.0000
swelling	031901	1	5987435	5987435	5987435	5987435.0000
interrelationships	036001	1	5987435	5987435	5987435	5987435.0000
riser	036002	1	28357832	28357832	28357832	28357832.0000
bee	038001	1	5987435	5987435	5987435	5987435.0000
kanji	038002	1	28357832	28357832	28357832	28357832.0000
dental	038003	1	39654943	39654943	39654943	39654943.0000
railway	038011	1	5987435	5987435	5987435	5987435.0000
validate	038012	1	28357832	28357832	28357832	28357832.0000
normalizes	038013	1	39654943	39654943	39654943	39654943.0000
Kline	038101	1	5987435	5987435	5987435	5987435.0000
Anatole	038102	1	28357832	28357832	28357832	28357832.0000
partridges	038103	1	39654943	39654943	39654943	39654943.0000
recruited	038201	1	5987435	5987435	5987435	5987435.0000
dimensions	038202	1	28357832	28357832	28357832	28357832.0000
Chicana	038203	1	39654943	39654943	39654943	39654943.0000
unknown's avatar
unknown committed
1799
select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3;
1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810
companynr	fld3	sum(price)
512	boat	786542
512	capably	786542
512	cupboard	786542
512	decliner	786542
512	descendants	786542
512	dopers	786542
512	erases	786542
512	Micronesia	786542
512	Miles	786542
512	skies	786542
unknown's avatar
unknown committed
1811
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;
1812 1813 1814 1815 1816
companynr	count(*)	min(fld3)	max(fld3)	sum(price)	avg(price)
00	1	Omaha	Omaha	5987435	5987435.0000
36	1	dubbed	dubbed	28357832	28357832.0000
37	83	Abraham	Wotan	1908978016	22999735.1325
50	2	scribbled	tapestry	68012775	34006387.5000
unknown's avatar
unknown committed
1817
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;
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905
t3.companynr+0	t2nr	fld3	sum(price)
37	1	Omaha	5987435
37	11401	breaking	5987435
37	11402	Romans	28357832
37	11403	intercepted	39654943
37	11501	bewilderingly	5987435
37	11701	astound	5987435
37	11702	admonishing	28357832
37	11703	sumac	39654943
37	12001	flanking	5987435
37	12003	combed	39654943
37	12301	Eulerian	5987435
37	12302	dubbed	28357832
37	12303	Kane	39654943
37	12501	annihilates	5987435
37	12602	Wotan	28357832
37	12603	snatching	39654943
37	12701	grazing	5987435
37	12702	Baird	28357832
37	12703	celery	39654943
37	13601	handgun	5987435
37	13602	foldout	28357832
37	13603	mystic	39654943
37	13801	intelligibility	5987435
37	13802	Augustine	28357832
37	13803	teethe	39654943
37	13901	scholastics	5987435
37	16001	audiology	5987435
37	16201	wallet	5987435
37	16202	parters	28357832
37	16301	eschew	5987435
37	16302	quitter	28357832
37	16303	neat	39654943
37	18001	jarring	5987435
37	18002	tinily	28357832
37	18003	balled	39654943
37	18012	impulsive	28357832
37	18013	starlet	39654943
37	18021	lawgiver	5987435
37	18022	stated	28357832
37	18023	readable	39654943
37	18032	testicle	28357832
37	18033	Parsifal	39654943
37	18041	Punjab	5987435
37	18042	Merritt	28357832
37	18043	Quixotism	39654943
37	18051	sureties	5987435
37	18052	puddings	28357832
37	18053	tapestry	39654943
37	18061	trimmings	5987435
37	18062	humility	28357832
37	18101	tragedies	5987435
37	18102	skulking	28357832
37	18103	flint	39654943
37	18201	relaxing	5987435
37	18202	offload	28357832
37	18402	suites	28357832
37	18403	lists	39654943
37	18601	vacuuming	5987435
37	18602	dentally	28357832
37	18603	humanness	39654943
37	18801	inch	5987435
37	18802	Weissmuller	28357832
37	18803	irresponsibly	39654943
37	18811	repetitions	5987435
37	18812	Antares	28357832
37	19101	ventilate	5987435
37	19102	pityingly	28357832
37	19103	interdependent	39654943
37	19201	Graves	5987435
37	30501	neonatal	5987435
37	30502	scribbled	28357832
37	30503	chafe	39654943
37	31901	realtor	5987435
37	36001	elite	5987435
37	36002	funereal	28357832
37	38001	Conley	5987435
37	38002	lectured	28357832
37	38003	Abraham	39654943
37	38011	groupings	5987435
37	38012	dissociate	28357832
37	38013	coexist	39654943
37	38101	rusting	5987435
37	38102	galling	28357832
37	38103	obliterates	39654943
37	38201	resumes	5987435
37	38202	analyzable	28357832
37	38203	terminator	39654943
unknown's avatar
unknown committed
1906
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;
1907 1908
sum(price)
234298
unknown's avatar
unknown committed
1909
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;
1910 1911
fld1	sum(price)
038008	234298
unknown's avatar
unknown committed
1912
explain select fld3 from t2 where 1>2 or 2>3;
unknown's avatar
unknown committed
1913
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1914
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
unknown's avatar
unknown committed
1915
explain select fld3 from t2 where fld1=fld1;
unknown's avatar
unknown committed
1916
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
unknown's avatar
unknown committed
1917
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
unknown's avatar
unknown committed
1918
select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502;
1919 1920 1921
companynr	fld1
34	250501
34	250502
unknown's avatar
unknown committed
1922
select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502;
1923 1924 1925
companynr	fld1
34	250501
34	250502
unknown's avatar
unknown committed
1926
select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000;
1927 1928 1929 1930 1931 1932
companynr	count	sum
00	82	10355753
29	95	14473298
34	70	17788966
37	588	83602098
41	52	12816335
unknown's avatar
unknown committed
1933
select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ;
1934 1935 1936 1937 1938 1939
companynr
00
29
34
37
41
unknown's avatar
unknown committed
1940
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40;
1941 1942 1943 1944 1945 1946 1947 1948
companynr	companyname	count(*)
68	company 10	12
50	company 11	11
40	company 5	37
41	company 6	52
53	company 7	4
58	company 8	23
65	company 9	10
unknown's avatar
unknown committed
1949
select count(*) from t2;
1950 1951
count(*)
1199
unknown's avatar
unknown committed
1952
select count(*) from t2 where fld1 < 098024;
1953 1954
count(*)
387
unknown's avatar
unknown committed
1955
select min(fld1) from t2 where fld1>= 098024;
1956 1957
min(fld1)
98024
unknown's avatar
unknown committed
1958
select max(fld1) from t2 where fld1>= 098024;
1959 1960
max(fld1)
1232609
unknown's avatar
unknown committed
1961
select count(*) from t3 where price2=76234234;
1962 1963
count(*)
4181
unknown's avatar
unknown committed
1964
select count(*) from t3 where companynr=512 and price2=76234234;
1965 1966
count(*)
4181
unknown's avatar
unknown committed
1967
explain select min(fld1),max(fld1),count(*) from t2;
unknown's avatar
unknown committed
1968
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1969
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
unknown's avatar
unknown committed
1970
select min(fld1),max(fld1),count(*) from t2;
1971 1972
min(fld1)	max(fld1)	count(*)
0	1232609	1199
unknown's avatar
unknown committed
1973
select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742;
1974 1975
min(t2nr)	max(t2nr)
2115	2115
unknown's avatar
unknown committed
1976
select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78;
1977 1978
count(*)	min(t2nr)	max(t2nr)
4181	4	41804
unknown's avatar
unknown committed
1979
select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20;
1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
t2nr	count(*)
9	1
19	1
29	1
39	1
49	1
59	1
69	1
79	1
89	1
99	1
109	1
119	1
129	1
139	1
149	1
159	1
169	1
179	1
189	1
199	1
unknown's avatar
unknown committed
2001
select max(t2nr) from t3 where price=983543950;
2002 2003
max(t2nr)
41807
unknown's avatar
unknown committed
2004
select t1.period from t3 = t1 limit 1;
2005 2006
period
1001
unknown's avatar
unknown committed
2007
select t1.period from t1 as t1 limit 1;
2008 2009
period
9410
unknown's avatar
unknown committed
2010
select t1.period as "Nuvarande period" from t1 as t1 limit 1;
2011 2012
Nuvarande period
9410
unknown's avatar
unknown committed
2013
select period as ok_period from t1 limit 1;
2014 2015
ok_period
9410
unknown's avatar
unknown committed
2016
select period as ok_period from t1 group by ok_period limit 1;
2017 2018
ok_period
9410
unknown's avatar
unknown committed
2019
select 1+1 as summa from t1 group by summa limit 1;
2020 2021
summa
2
unknown's avatar
unknown committed
2022
select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1;
2023 2024
Nuvarande period
9410
unknown's avatar
unknown committed
2025
show tables;
2026 2027 2028 2029 2030
Tables_in_test
t1
t2
t3
t4
unknown's avatar
unknown committed
2031
show tables from test like "s%";
2032
Tables_in_test (s%)
unknown's avatar
unknown committed
2033
show tables from test like "t?";
2034
Tables_in_test (t?)
unknown's avatar
unknown committed
2035
show full columns from t2;
2036
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
2037 2038 2039 2040 2041 2042 2043
auto	int(11)	NULL	NO	PRI	NULL	auto_increment	select,insert,update,references	
fld1	int(6) unsigned zerofill	NULL	NO	UNI	000000		select,insert,update,references	
companynr	tinyint(2) unsigned zerofill	NULL	NO		00		select,insert,update,references	
fld3	char(30)	latin1_swedish_ci	NO	MUL			select,insert,update,references	
fld4	char(35)	latin1_swedish_ci	NO				select,insert,update,references	
fld5	char(35)	latin1_swedish_ci	NO				select,insert,update,references	
fld6	char(4)	latin1_swedish_ci	NO				select,insert,update,references	
unknown's avatar
unknown committed
2044
show full columns from t2 from test like 'f%';
2045
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
2046 2047 2048 2049 2050
fld1	int(6) unsigned zerofill	NULL	NO	UNI	000000		select,insert,update,references	
fld3	char(30)	latin1_swedish_ci	NO	MUL			select,insert,update,references	
fld4	char(35)	latin1_swedish_ci	NO				select,insert,update,references	
fld5	char(35)	latin1_swedish_ci	NO				select,insert,update,references	
fld6	char(4)	latin1_swedish_ci	NO				select,insert,update,references	
unknown's avatar
unknown committed
2051
show full columns from t2 from test like 's%';
2052
Field	Type	Collation	Null	Key	Default	Extra	Privileges	Comment
unknown's avatar
unknown committed
2053
show keys from t2;
2054 2055 2056 2057
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
t2	0	PRIMARY	1	auto	A	1199	NULL	NULL		BTREE	
t2	0	fld1	1	fld1	A	1199	NULL	NULL		BTREE	
t2	1	fld3	1	fld3	A	NULL	NULL	NULL		BTREE	
2058
drop table t4, t3, t2, t1;
unknown's avatar
unknown committed
2059 2060
DO 1;
DO benchmark(100,1+1),1,1;
2061 2062 2063 2064
do default;
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 '' at line 1
do foobar;
ERROR 42S22: Unknown column 'foobar' in 'field list'
unknown's avatar
unknown committed
2065 2066 2067 2068 2069 2070 2071 2072
CREATE TABLE t1 (
id mediumint(8) unsigned NOT NULL auto_increment,
pseudo varchar(35) NOT NULL default '',
PRIMARY KEY  (id),
UNIQUE KEY pseudo (pseudo)
);
INSERT INTO t1 (pseudo) VALUES ('test');
INSERT INTO t1 (pseudo) VALUES ('test1');
unknown's avatar
unknown committed
2073 2074
SELECT 1 as rnd1 from t1 where rand() > 2;
rnd1
unknown's avatar
unknown committed
2075
DROP TABLE t1;
unknown's avatar
unknown committed
2076
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(14) NOT NULL,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
2077
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);
unknown's avatar
unknown committed
2078
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;
2079
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
2080 2081 2082
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;
gvid	the_success	the_fail	the_size	the_time
Warnings:
unknown's avatar
unknown committed
2083 2084
Warning	1292	Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1
Warning	1292	Incorrect datetime value: 'wrong-date-value' for column 'sampletime' at row 1
2085
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;
2086 2087
gvid	the_success	the_fail	the_size	the_time
DROP TABLE t1,t2;
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102
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');
INSERT INTO t1 VALUES (102935998719055004,'brade',1029359987,2,102935229116544068,102935229216544093);
select wss_type from t1 where wss_type ='102935229216544106';
wss_type
select wss_type from t1 where wss_type ='102935229216544105';
wss_type
select wss_type from t1 where wss_type ='102935229216544104';
wss_type
select wss_type from t1 where wss_type ='102935229216544093';
wss_type
102935229216544093
select wss_type from t1 where wss_type =102935229216544093;
wss_type
102935229216544093
drop table t1;
unknown's avatar
unknown committed
2103 2104 2105 2106 2107 2108 2109 2110 2111
select 1+2,"aaaa",3.13*2.0 into @a,@b,@c;
select @a;
@a
3
select @b;
@b
aaaa
select @c;
@c
unknown's avatar
unknown committed
2112
6.260
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138
create table t1 (a int not null auto_increment primary key);
insert into t1 values ();
insert into t1 values ();
insert into t1 values ();
select * from (t1 as t2 left join t1 as t3 using (a)), t1;
a	a	a
1	1	1
2	2	1
3	3	1
1	1	2
2	2	2
3	3	2
1	1	3
2	2	3
3	3	3
select * from t1, (t1 as t2 left join t1 as t3 using (a));
a	a	a
1	1	1
2	1	1
3	1	1
1	2	2
2	2	2
3	2	2
1	3	3
2	3	3
3	3	3
2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
a	a	a
1	1	1
2	2	1
3	3	1
1	1	2
2	2	2
3	3	2
1	1	3
2	2	3
3	3	3
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
a	a	a
1	1	1
2	1	1
3	1	1
1	2	2
2	2	2
3	2	2
1	3	3
2	3	3
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
a	a	a
1	1	2
2164 2165
2	2	2
3	3	2
unknown's avatar
unknown committed
2166 2167
1	1	3
2	2	3
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196
3	3	3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a	a
2	1	1
3	1	1
2	2	2
3	2	2
2	3	3
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) left outer join t1 on t1.a>1;
a	a	a
1	1	2
1	1	3
2	2	2
2	2	3
3	3	2
3	3	3
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a	a
2197
1	NULL	NULL
2198 2199 2200
2	1	1
2	2	2
2	3	3
2201 2202
3	1	1
3	2	2
2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) left join t1 using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 left join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 natural left join (t1 as t2 left join t1 as t3 using (a));
a	a	a
1	1	1
2	2	2
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) right join t1 on t1.a>1;
a	a	a
2226
NULL	NULL	1
2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261
1	1	2
2	2	2
3	3	2
1	1	3
2	2	3
3	3	3
select * from t1 right join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a	a
2	1	1
3	1	1
2	2	2
3	2	2
2	3	3
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) right outer join t1 using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 right outer join (t1 as t2 left join t1 as t3 using (a)) using ( a );
a	a	a
1	1	1
2	2	2
3	3	3
select * from (t1 as t2 left join t1 as t3 using (a)) natural right join t1;
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 natural right join (t1 as t2 left join t1 as t3 using (a));
a	a	a
1	1	1
2	2	2
3	3	3
select * from t1 natural join (t1 as t2 left join t1 as t3 using (a));
2262 2263 2264 2265
a	a
1	1
2	2
3	3
2266
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
unknown's avatar
unknown committed
2267 2268 2269 2270
a	a
1	1
2	2
3	3
2271
drop table t1;
unknown's avatar
unknown committed
2272
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;
2273
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);
unknown's avatar
unknown committed
2274
CREATE TABLE t2 ( id int(11) NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
2275 2276 2277 2278 2279 2280 2281 2282
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
aa	id	t2_id	id
2	8299	2517	2517
3	8301	2518	2518
4	8302	2519	2519
5	8303	2520	2520
6	8304	2521	2521
2283
drop table t1,t2;
2284 2285 2286 2287 2288 2289 2290 2291 2292 2293
create table t1 (id1 int NOT NULL);
create table t2 (id2 int NOT NULL);
create table t3 (id3 int NOT NULL);
create table t4 (id4 int NOT NULL, id44 int NOT NULL, KEY (id4));
insert into t1 values (1);
insert into t1 values (2);
insert into t2 values (1);
insert into t4 values (1,1);
explain select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
unknown's avatar
unknown committed
2294 2295 2296
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t3	system	NULL	NULL	NULL	NULL	0	const row not found
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
unknown's avatar
unknown committed
2297 2298
1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	
1	SIMPLE	t4	ALL	id4	NULL	NULL	NULL	1	Using where
2299 2300 2301 2302 2303
select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
id1	id2	id3	id4	id44
1	1	NULL	NULL	NULL
drop table t1,t2,t3,t4;
2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315
create table t1(s varchar(10) not null);
create table t2(s varchar(10) not null primary key);
create table t3(s varchar(10) not null primary key);
insert into t1 values ('one\t'), ('two\t');
insert into t2 values ('one\r'), ('two\t');
insert into t3 values ('one '), ('two\t');
select * from t1 where s = 'one';
s
select * from t2 where s = 'one';
s
select * from t3 where s = 'one';
s
2316
one 
2317 2318 2319 2320 2321 2322 2323
select * from t1,t2 where t1.s = t2.s;
s	s
two		two	
select * from t2,t3 where t2.s = t3.s;
s	s
two		two	
drop table t1, t2, t3;
unknown's avatar
unknown committed
2324 2325 2326 2327 2328
create table t1 (a integer,  b integer, index(a), index(b));
create table t2 (c integer,  d integer, index(c), index(d));
insert into t1 values (1,2), (2,2), (3,2), (4,2);
insert into t2 values (1,3), (2,3), (3,4), (4,4);
explain select * from t1 left join t2 on a=c where d in (4);
unknown's avatar
unknown committed
2329 2330 2331
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	c,d	d	5	const	2	Using where
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	3	Using where
unknown's avatar
unknown committed
2332 2333 2334 2335 2336
select * from t1 left join t2 on a=c where d in (4);
a	b	c	d
3	2	3	4
4	2	4	4
explain select * from t1 left join t2 on a=c where d = 4;
unknown's avatar
unknown committed
2337 2338 2339
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t2	ref	c,d	d	5	const	2	Using where
1	SIMPLE	t1	ALL	a	NULL	NULL	NULL	3	Using where
unknown's avatar
unknown committed
2340 2341 2342 2343 2344
select * from t1 left join t2 on a=c where d = 4;
a	b	c	d
3	2	3	4
4	2	4	4
drop table t1, t2;
unknown's avatar
unknown committed
2345 2346 2347 2348 2349
CREATE TABLE t1 (
i int(11) NOT NULL default '0',
c char(10) NOT NULL default '',
PRIMARY KEY  (i),
UNIQUE KEY c (c)
unknown's avatar
unknown committed
2350
) ENGINE=MyISAM;
unknown's avatar
unknown committed
2351 2352 2353 2354
INSERT INTO t1 VALUES (1,'a');
INSERT INTO t1 VALUES (2,'b');
INSERT INTO t1 VALUES (3,'c');
EXPLAIN SELECT i FROM t1 WHERE i=1;
unknown's avatar
unknown committed
2355 2356
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	const	PRIMARY	PRIMARY	4	const	1	Using index
unknown's avatar
unknown committed
2357
DROP TABLE t1;
unknown's avatar
unknown committed
2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390
CREATE TABLE t1 ( 
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', 
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', 
F2I4 int(11) NOT NULL default '0' 
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO t1 VALUES 
('W%RT', '0100',  1), 
('W-RT', '0100', 1), 
('WART', '0100', 1), 
('WART', '0200', 1), 
('WERT', '0100', 2), 
('WORT','0200', 2), 
('WT', '0100', 2), 
('W_RT', '0100', 2), 
('WaRT', '0100', 3), 
('WART', '0300', 3), 
('WRT' , '0400', 3), 
('WURM', '0500', 3), 
('W%T', '0600', 4), 
('WA%T', '0700', 4), 
('WA_T', '0800', 4);
SELECT K2C4, K4N4, F2I4 FROM t1
WHERE  K2C4 = 'WART' AND 
(F2I4 = 2 AND K2C4 = 'WART' OR (F2I4 = 2 OR K4N4 = '0200'));
K2C4	K4N4	F2I4
WART	0200	1
SELECT K2C4, K4N4, F2I4 FROM t1
WHERE  K2C4 = 'WART' AND (K2C4 = 'WART' OR K4N4 = '0200');
K2C4	K4N4	F2I4
WART	0100	1
WART	0200	1
WART	0300	3
DROP TABLE t1;