1
drop table if exists t1,t2,t3;
2
CREATE TABLE t1 (id int,facility char(20));
3
CREATE TABLE t2 (facility char(20));
4
INSERT INTO t1 VALUES (NULL,NULL);
5
INSERT INTO t1 VALUES (-1,'');
6
INSERT INTO t1 VALUES (0,'');
7
INSERT INTO t1 VALUES (1,'/L');
8
INSERT INTO t1 VALUES (2,'A01');
9
INSERT INTO t1 VALUES (3,'ANC');
10
INSERT INTO t1 VALUES (4,'F01');
11
INSERT INTO t1 VALUES (5,'FBX');
12
INSERT INTO t1 VALUES (6,'MT');
13
INSERT INTO t1 VALUES (7,'P');
14
INSERT INTO t1 VALUES (8,'RV');
15
INSERT INTO t1 VALUES (9,'SRV');
16
INSERT INTO t1 VALUES (10,'VMT');
17
INSERT INTO t2 SELECT DISTINCT FACILITY FROM t1;
18
select id from t1 group by id;
33
select * from t1 order by id;
48
select id-5,facility from t1 order by "id-5";
63
select id,concat(facility) from t1 group by id ;
78
select id+0 as a,max(id),concat(facility) as b from t1 group by a order by b desc,a;
93
select id >= 0 and id <= 5 as grp,count(*) from t1 group by grp;
98
SELECT DISTINCT FACILITY FROM t1;
112
SELECT FACILITY FROM t2;
126
SELECT count(*) from t1,t2 where t1.facility=t2.facility;
129
select count(facility) from t1;
132
select count(*) from t1;
135
select count(*) from t1 where facility IS NULL;
138
select count(*) from t1 where facility = NULL;
141
select count(*) from t1 where facility IS NOT NULL;
144
select count(*) from t1 where id IS NULL;
147
select count(*) from t1 where id IS NOT NULL;
151
CREATE TABLE t1 (UserId int DEFAULT '0' NOT NULL);
152
INSERT INTO t1 VALUES (20);
153
INSERT INTO t1 VALUES (27);
154
SELECT UserId FROM t1 WHERE Userid=22;
156
SELECT UserId FROM t1 WHERE UserId=22 group by Userid;
158
SELECT DISTINCT UserId FROM t1 WHERE UserId=22 group by Userid;
160
SELECT DISTINCT UserId FROM t1 WHERE UserId=22;
163
CREATE TABLE t1 (a int not null primary key,b int);
164
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1);
165
CREATE TABLE t2 (a int not null, key (A));
166
INSERT INTO t2 VALUES (1),(2);
167
CREATE TABLE t3 (a int, key(A), b text);
168
INSERT INTO t3 VALUES (1,'1'),(2,'2');
169
SELECT DISTINCT t3.b FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
172
INSERT INTO t2 values (1),(2),(3);
173
INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2');
174
explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
175
id select_type table type possible_keys key key_len ref rows Extra
176
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using temporary
177
1 SIMPLE t2 ref a a 4 test.t1.a 1
178
1 SIMPLE t3 ref a a 5 test.t1.b 1
179
SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
182
create temporary table t4 select * from t3;
183
insert into t3 select * from t4;
184
insert into t4 select * from t3;
185
insert into t3 select * from t4;
186
insert into t4 select * from t3;
187
insert into t3 select * from t4;
188
insert into t4 select * from t3;
189
insert into t3 select * from t4;
190
explain select distinct t1.a from t1,t3 where t1.a=t3.a;
191
id select_type table type possible_keys key key_len ref rows Extra
192
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using temporary
193
1 SIMPLE t3 ref a a 5 test.t1.a 1 Distinct
194
select distinct t1.a from t1,t3 where t1.a=t3.a;
198
show status like 'Handler%';
208
Handler_read_rnd_next #
211
Handler_savepoint_rollback #
215
select distinct 1 from t1,t3 where t1.a=t3.a;
218
show status like 'Handler%';
228
Handler_read_rnd_next #
231
Handler_savepoint_rollback #
234
explain SELECT distinct t1.a from t1;
235
id select_type table type possible_keys key key_len ref rows Extra
236
1 SIMPLE t1 ALL NULL NULL NULL NULL 4
237
explain SELECT distinct t1.a from t1 order by a desc;
238
id select_type table type possible_keys key key_len ref rows Extra
239
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
240
explain SELECT t1.a from t1 group by a order by a desc;
241
id select_type table type possible_keys key key_len ref rows Extra
242
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
243
explain SELECT distinct t1.a from t1 order by a desc limit 1;
244
id select_type table type possible_keys key key_len ref rows Extra
245
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort
246
explain SELECT distinct a from t3 order by a desc limit 2;
247
id select_type table type possible_keys key key_len ref rows Extra
248
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
249
explain SELECT distinct a,b from t3 order by a+1;
250
id select_type table type possible_keys key key_len ref rows Extra
251
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
252
explain SELECT distinct a,b from t3 order by a limit 2;
253
id select_type table type possible_keys key key_len ref rows Extra
254
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
255
explain SELECT a,b from t3 group by a,b order by a+1;
256
id select_type table type possible_keys key key_len ref rows Extra
257
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
258
drop table t1,t2,t3,t4;
259
CREATE TABLE t1 (name varchar(255));
260
INSERT INTO t1 VALUES ('aa'),('ab'),('ac'),('ad'),('ae');
261
SELECT DISTINCT * FROM t1 LIMIT 2;
265
SELECT DISTINCT name FROM t1 LIMIT 2;
269
SELECT DISTINCT 1 FROM t1 LIMIT 2;
274
ID int NOT NULL auto_increment,
275
NAME varchar(75) DEFAULT '' NOT NULL,
276
LINK_ID int DEFAULT '0' NOT NULL,
279
KEY LINK_ID (LINK_ID)
281
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0),(2,'Jack',0),(3,'Bill',0);
283
ID int NOT NULL auto_increment,
284
NAME varchar(150) DEFAULT '' NOT NULL,
289
t2.id AS key_link_id,
292
LEFT JOIN t2 ON t1.link_id=t2.id
300
name tinytext not null,
313
insert into t1 values (1,'yes'), (2,'no');
314
insert into t2 values (1,1);
315
insert into t3 values (1,1);
326
t1 as j_lj_t2 left join t2 as t2_lj
327
on j_lj_t2.id=t2_lj.id
329
t1 as j_lj_t3 left join t3 as t3_lj
330
on j_lj_t3.id=t3_lj.id
332
((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2))
333
AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2));
334
id select_type table type possible_keys key key_len ref rows Extra
335
1 SIMPLE t1 ALL id NULL NULL NULL 2 Using temporary
336
1 SIMPLE t2 ALL id NULL NULL NULL 1 Distinct; Using join buffer
337
1 SIMPLE t3 ALL id NULL NULL NULL 1 Distinct; Using join buffer
338
1 SIMPLE j_lj_t2 ALL id NULL NULL NULL 2 Using where; Distinct; Using join buffer
339
1 SIMPLE t2_lj ref id id 4 test.j_lj_t2.id 1 Using where; Distinct
340
1 SIMPLE j_lj_t3 ALL id NULL NULL NULL 2 Using where; Distinct; Using join buffer
341
1 SIMPLE t3_lj ref id id 4 test.j_lj_t3.id 1 Using where; Distinct
351
t1 as j_lj_t2 left join t2 as t2_lj
352
on j_lj_t2.id=t2_lj.id
354
t1 as j_lj_t3 left join t3 as t3_lj
355
on j_lj_t3.id=t3_lj.id
357
((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2))
358
AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2));
362
create table t1 (a int not null,b char(5), c text);
363
insert into t1 (a) values (1),(2),(3),(4),(1),(2),(3),(4);
364
select distinct a from t1 group by b,a having a > 2 order by a desc;
368
select distinct a,c from t1 group by b,c,a having a > 2 order by a desc;
373
create table t1 (a char(1), key(a));
374
insert into t1 values('1'),('1');
375
select * from t1 where a >= '1';
379
select distinct a from t1 order by a desc;
382
select distinct a from t1 where a >= '1' order by a desc;
386
CREATE TABLE t1 (email varchar(50), infoID BIGINT, dateentered DATETIME);
387
CREATE TABLE t2 (infoID BIGINT, shipcode varchar(10));
388
INSERT INTO t1 (email, infoID, dateentered) VALUES
389
('test1@testdomain.com', 1, '2002-07-30 22:56:38'),
390
('test1@testdomain.com', 1, '2002-07-27 22:58:16'),
391
('test2@testdomain.com', 1, '2002-06-19 15:22:19'),
392
('test2@testdomain.com', 2, '2002-06-18 14:23:47'),
393
('test3@testdomain.com', 1, '2002-05-19 22:17:32');
394
INSERT INTO t2(infoID, shipcode) VALUES
397
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID;
399
test1@testdomain.com Z001
400
test2@testdomain.com Z001
401
test2@testdomain.com R002
402
test3@testdomain.com Z001
403
SELECT DISTINCTROW email FROM t1 ORDER BY dateentered DESC;
408
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID ORDER BY dateentered DESC;
410
test1@testdomain.com Z001
411
test2@testdomain.com Z001
412
test2@testdomain.com R002
413
test3@testdomain.com Z001
415
CREATE TABLE t1 (privatemessageid int NOT NULL auto_increment, folderid int NOT NULL default '0', userid int NOT NULL default '0', touserid int NOT NULL default '0', fromuserid int NOT NULL default '0', title varchar(250) NOT NULL default '', message mediumtext NOT NULL, dateline int NOT NULL default '0', showsignature int NOT NULL default '0', iconid int NOT NULL default '0', messageread int NOT NULL default '0', readtime int NOT NULL default '0', receipt int NOT NULL default '0', deleteprompt int NOT NULL default '0', multiplerecipients int NOT NULL default '0', PRIMARY KEY (privatemessageid), KEY userid (userid));
416
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
417
CREATE TABLE t2 (userid int NOT NULL auto_increment, usergroupid int NOT NULL default '0', username varchar(50) NOT NULL default '', password varchar(50) NOT NULL default '', email varchar(50) NOT NULL default '', styleid int NOT NULL default '0', parentemail varchar(50) NOT NULL default '', coppauser int NOT NULL default '0', homepage varchar(100) NOT NULL default '', icq varchar(20) NOT NULL default '', aim varchar(20) NOT NULL default '', yahoo varchar(20) NOT NULL default '', signature mediumtext NOT NULL, adminemail int NOT NULL default '0', showemail int NOT NULL default '0', invisible int NOT NULL default '0', usertitle varchar(250) NOT NULL default '', customtitle int NOT NULL default '0', joindate int NOT NULL default '0', cookieuser int NOT NULL default '0', daysprune int NOT NULL default '0', lastvisit int NOT NULL default '0', lastactivity int NOT NULL default '0', lastpost int NOT NULL default '0', posts int NOT NULL default '0', timezoneoffset varchar(4) NOT NULL default '', emailnotification int NOT NULL default '0', buddylist mediumtext NOT NULL, ignorelist mediumtext NOT NULL, pmfolders mediumtext NOT NULL, receivepm int NOT NULL default '0', emailonpm int NOT NULL default '0', pmpopup int NOT NULL default '0', avatarid int NOT NULL default '0', avatarrevision int NOT NULL default '0', options int NOT NULL default '15', birthday date NULL, maxposts int NOT NULL default '-1', startofweek int NOT NULL default '1', ipaddress varchar(20) NOT NULL default '', referrerid int NOT NULL default '0', nosessionhash int NOT NULL default '0', autorefresh int NOT NULL default '-1', messagepopup int NOT NULL default '0', inforum int NOT NULL default '0', ratenum int NOT NULL default '0', ratetotal int NOT NULL default '0', allowrate int NOT NULL default '1', PRIMARY KEY (userid), KEY usergroupid (usergroupid), KEY username (username), KEY inforum (inforum));
418
INSERT INTO t2 VALUES (33,6,'Kevin','0','kevin@stileproject.com',1,'',0,'http://www.stileproject.com','','','','',1,1,0,'Administrator',0,996120694,1,-1,1030996168,1031027028,1030599436,36,'-6',0,'','','',1,0,1,0,0,15,NULL,-1,1,'64.0.0.0',0,1,-1,0,0,4,19,1);
419
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
420
privatemessageid folderid userid touserid fromuserid title message dateline showsignature iconid messageread readtime receipt deleteprompt multiplerecipients userid usergroupid username password email styleid parentemail coppauser homepage icq aim yahoo signature adminemail showemail invisible usertitle customtitle joindate cookieuser daysprune lastvisit lastactivity lastpost posts timezoneoffset emailnotification buddylist ignorelist pmfolders receivepm emailonpm pmpopup avatarid avatarrevision options birthday maxposts startofweek ipaddress referrerid nosessionhash autorefresh messagepopup inforum ratenum ratetotal allowrate
421
128 0 33 33 8 :D 996121863 1 0 2 996122850 2 0 0 33 6 Kevin 0 kevin@stileproject.com 1 0 http://www.stileproject.com 1 1 0 Administrator 0 996120694 1 -1 1030996168 1031027028 1030599436 36 -6 0 1 0 1 0 0 15 NULL -1 1 64.0.0.0 0 1 -1 0 0 4 19 1
423
CREATE TABLE t1 (a int primary key, b int, c int);
424
INSERT t1 VALUES (1,2,3);
425
CREATE TABLE t2 (a int primary key, b int, c int);
426
INSERT t2 VALUES (3,4,5);
427
SELECT DISTINCT t1.a, t2.b FROM t1, t2 WHERE t1.a=1 ORDER BY t2.c;
431
CREATE table t1 ( `id` int NOT NULL auto_increment, `name` varchar(50) NOT NULL default '', PRIMARY KEY (`id`)) AUTO_INCREMENT=3 ;
432
INSERT INTO t1 VALUES (1, 'aaaaa');
433
INSERT INTO t1 VALUES (3, 'aaaaa');
434
INSERT INTO t1 VALUES (2, 'eeeeeee');
435
select distinct left(name,1) as name from t1;
441
ID int NOT NULL auto_increment,
442
NAME varchar(75) DEFAULT '' NOT NULL,
443
LINK_ID int DEFAULT '0' NOT NULL,
446
KEY LINK_ID (LINK_ID)
448
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0);
449
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (2,'Jack',0);
450
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (3,'Bill',0);
452
ID int NOT NULL auto_increment,
453
NAME varchar(150) DEFAULT '' NOT NULL,
458
t2.id AS key_link_id,
461
LEFT JOIN t2 ON t1.link_id=t2.id
468
html varchar(5) default NULL,
472
INSERT INTO t1 VALUES ('1',1,0);
473
SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
477
CREATE TABLE t1 (a int);
478
INSERT INTO t1 VALUES (1),(2),(3),(4),(5);
479
SELECT DISTINCT a, 1 FROM t1;
486
SELECT DISTINCT 1, a FROM t1;
493
CREATE TABLE t2 (a int, b int);
494
INSERT INTO t2 VALUES (1,1),(2,2),(2,3),(2,4),(3,5);
495
SELECT DISTINCT a, b, 2 FROM t2;
502
SELECT DISTINCT 2, a, b FROM t2;
509
SELECT DISTINCT a, 2, b FROM t2;
517
CREATE TABLE t1(a INT PRIMARY KEY, b INT);
518
INSERT INTO t1 VALUES (1,1), (2,1), (3,1);
519
EXPLAIN SELECT DISTINCT a FROM t1;
520
id select_type table type possible_keys key key_len ref rows Extra
521
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
522
EXPLAIN SELECT DISTINCT a,b FROM t1;
523
id select_type table type possible_keys key key_len ref rows Extra
524
1 SIMPLE t1 ALL NULL NULL NULL NULL 3
525
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2;
526
id select_type table type possible_keys key key_len ref rows Extra
527
1 SIMPLE t1_1 ALL NULL NULL NULL NULL 3 Using temporary
528
1 SIMPLE t1_2 ALL NULL NULL NULL NULL 3 Distinct; Using join buffer
529
EXPLAIN SELECT DISTINCT t1_1.a, t1_1.b FROM t1 t1_1, t1 t1_2
530
WHERE t1_1.a = t1_2.a;
531
id select_type table type possible_keys key key_len ref rows Extra
532
1 SIMPLE t1_1 ALL PRIMARY NULL NULL NULL 3 Using temporary
533
1 SIMPLE t1_2 eq_ref PRIMARY PRIMARY 4 test.t1_1.a 1 Distinct
534
EXPLAIN SELECT a FROM t1 GROUP BY a;
535
id select_type table type possible_keys key key_len ref rows Extra
536
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
537
EXPLAIN SELECT a,b FROM t1 GROUP BY a,b;
538
id select_type table type possible_keys key key_len ref rows Extra
539
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
540
EXPLAIN SELECT DISTINCT a,b FROM t1 GROUP BY a,b;
541
id select_type table type possible_keys key key_len ref rows Extra
542
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
543
CREATE TABLE t2(a INT, b INT NOT NULL, c INT NOT NULL, d INT,
545
INSERT INTO t2 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
546
EXPLAIN SELECT DISTINCT a FROM t2;
547
id select_type table type possible_keys key key_len ref rows Extra
548
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using temporary
549
EXPLAIN SELECT DISTINCT a,a FROM t2;
550
id select_type table type possible_keys key key_len ref rows Extra
551
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using temporary
552
EXPLAIN SELECT DISTINCT b,a FROM t2;
553
id select_type table type possible_keys key key_len ref rows Extra
554
1 SIMPLE t2 ALL NULL NULL NULL NULL 3
555
EXPLAIN SELECT DISTINCT a,c FROM t2;
556
id select_type table type possible_keys key key_len ref rows Extra
557
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using temporary
558
EXPLAIN SELECT DISTINCT c,a,b FROM t2;
559
id select_type table type possible_keys key key_len ref rows Extra
560
1 SIMPLE t2 ALL NULL NULL NULL NULL 3
561
EXPLAIN SELECT DISTINCT a,b,d FROM t2 GROUP BY c,b,d;
562
id select_type table type possible_keys key key_len ref rows Extra
563
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort
564
CREATE UNIQUE INDEX c_b_unq ON t2 (c,b);
565
EXPLAIN SELECT DISTINCT a,b,d FROM t2 GROUP BY c,b,d;
566
id select_type table type possible_keys key key_len ref rows Extra
567
1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using filesort
569
create table t1 (id int, dsc varchar(50));
570
insert into t1 values (1, "line number one"), (2, "line number two"), (3, "line number three");
571
select distinct id, IFNULL(dsc, '-') from t1;
577
CREATE TABLE t1 (a int primary key, b int);
578
INSERT INTO t1 (a,b) values (1,1), (2,3), (3,2);
579
explain SELECT DISTINCT a, b FROM t1 ORDER BY b;
580
id select_type table type possible_keys key key_len ref rows Extra
581
1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
582
SELECT DISTINCT a, b FROM t1 ORDER BY b;
589
ID int NOT NULL auto_increment,
590
x varchar(20) default NULL,
591
y decimal(10,0) default NULL,
595
INSERT INTO t1 VALUES
602
select count(distinct x,y) from t1;
605
select count(distinct concat(x,y)) from t1;
606
count(distinct concat(x,y))
609
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a,b));
610
INSERT INTO t1 VALUES (1, 101);
611
INSERT INTO t1 SELECT a + 1, a + 101 FROM t1;
612
INSERT INTO t1 SELECT a + 2, a + 102 FROM t1;
613
INSERT INTO t1 SELECT a + 4, a + 104 FROM t1;
614
INSERT INTO t1 SELECT a + 8, a + 108 FROM t1;
615
EXPLAIN SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
616
id select_type table type possible_keys key key_len ref rows Extra
617
1 SIMPLE t1 ALL NULL NULL NULL NULL 16 Using where; Using temporary; Using filesort
618
SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
621
CREATE TABLE t1 (a INT, UNIQUE (a));
622
INSERT INTO t1 VALUES (4),(null),(2),(1),(null),(3);
623
EXPLAIN SELECT DISTINCT a FROM t1;
624
id select_type table type possible_keys key key_len ref rows Extra
625
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary
626
SELECT DISTINCT a FROM t1;
633
EXPLAIN SELECT a FROM t1 GROUP BY a;
634
id select_type table type possible_keys key key_len ref rows Extra
635
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort
636
SELECT a FROM t1 GROUP BY a;
644
CREATE TABLE t1 (a INT, b INT);
645
INSERT INTO t1 VALUES(1,1),(1,2),(1,3);
646
SELECT DISTINCT a, b FROM t1;
651
SELECT DISTINCT a, a, b FROM t1;
658
CREATE TABLE t1(a INT, b INT, c INT, d INT DEFAULT 0, e INT DEFAULT 0,
659
PRIMARY KEY(a,b,c,d,e),
662
INSERT INTO t1(a, b, c) VALUES (1, 1, 1),
668
EXPLAIN SELECT DISTINCT a, b, d, c FROM t1;
669
id select_type table type possible_keys key key_len ref rows Extra
670
1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary
671
SELECT DISTINCT a, b, d, c FROM t1;