~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/distinct.result

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
SELECT DISTINCT UserId FROM t1 WHERE UserId=22;
161
161
UserId
162
162
drop table t1;
163
 
CREATE TABLE t1 (a int unsigned not null primary key,b int unsigned);
 
163
CREATE TABLE t1 (a int not null primary key,b int);
164
164
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1);
165
 
CREATE TABLE t2 (a int unsigned not null, key (A));
 
165
CREATE TABLE t2 (a int not null, key (A));
166
166
INSERT INTO t2 VALUES (1),(2);
167
 
CREATE TABLE t3 (a int unsigned, key(A), b text);
 
167
CREATE TABLE t3 (a int, key(A), b text);
168
168
INSERT INTO t3 VALUES (1,'1'),(2,'2');
169
169
SELECT DISTINCT t3.b FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
170
170
b
326
326
id
327
327
2
328
328
drop table t1,t2,t3;
329
 
create table t1 (a int not null, b int not null, t time);
330
 
insert into t1 values (1,1,"00:06:15"),(1,2,"00:06:15"),(1,2,"00:30:15"),(1,3,"00:06:15"),(1,3,"00:30:15");
331
 
select a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
332
 
a       sec_to_time(sum(time_to_sec(t)))
333
 
1       00:06:15
334
 
1       00:36:30
335
 
1       00:36:30
336
 
select distinct a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
337
 
a       sec_to_time(sum(time_to_sec(t)))
338
 
1       00:06:15
339
 
1       00:36:30
340
 
create table t2 (a int not null primary key, b int);
341
 
insert into t2 values (1,1),(2,2),(3,3);
342
 
select t1.a,sec_to_time(sum(time_to_sec(t))) from t1 left join t2 on (t1.b=t2.a) group by t1.a,t2.b;
343
 
a       sec_to_time(sum(time_to_sec(t)))
344
 
1       00:06:15
345
 
1       00:36:30
346
 
1       00:36:30
347
 
select distinct t1.a,sec_to_time(sum(time_to_sec(t))) from t1 left join t2 on (t1.b=t2.a) group by t1.a,t2.b;
348
 
a       sec_to_time(sum(time_to_sec(t)))
349
 
1       00:06:15
350
 
1       00:36:30
351
 
drop table t1,t2;
352
329
create table t1 (a int not null,b char(5), c text);
353
330
insert into t1 (a) values (1),(2),(3),(4),(1),(2),(3),(4);
354
331
select distinct a from t1 group by b,a having a > 2 order by a desc;
360
337
4       NULL
361
338
3       NULL
362
339
drop table t1;
363
 
create table t1 (a char(1), key(a)) engine=myisam;
 
340
create table t1 (a char(1), key(a));
364
341
insert into t1 values('1'),('1');
365
342
select * from t1 where a >= '1';
366
343
a
402
379
test2@testdomain.com    R002
403
380
test3@testdomain.com    Z001
404
381
drop table t1,t2;
405
 
CREATE TABLE t1 (privatemessageid int unsigned NOT NULL auto_increment,  folderid smallint NOT NULL default '0',  userid int unsigned NOT NULL default '0',  touserid int unsigned NOT NULL default '0',  fromuserid int unsigned NOT NULL default '0',  title varchar(250) NOT NULL default '',  message mediumtext NOT NULL,  dateline int unsigned NOT NULL default '0',  showsignature smallint NOT NULL default '0',  iconid smallint unsigned NOT NULL default '0',  messageread smallint NOT NULL default '0',  readtime int unsigned NOT NULL default '0',  receipt smallint unsigned NOT NULL default '0',  deleteprompt smallint unsigned NOT NULL default '0',  multiplerecipients smallint unsigned NOT NULL default '0',  PRIMARY KEY  (privatemessageid),  KEY userid (userid)) ENGINE=MyISAM;
 
382
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));
406
383
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
407
 
CREATE TABLE t2 (userid int unsigned NOT NULL auto_increment,  usergroupid smallint unsigned NOT NULL default '0',  username varchar(50) NOT NULL default '',  password varchar(50) NOT NULL default '',  email varchar(50) NOT NULL default '',  styleid smallint unsigned NOT NULL default '0',  parentemail varchar(50) NOT NULL default '',  coppauser smallint 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 smallint NOT NULL default '0',  showemail smallint NOT NULL default '0',  invisible smallint NOT NULL default '0',  usertitle varchar(250) NOT NULL default '',  customtitle smallint NOT NULL default '0',  joindate int unsigned NOT NULL default '0',  cookieuser smallint NOT NULL default '0',  daysprune smallint NOT NULL default '0',  lastvisit int unsigned NOT NULL default '0',  lastactivity int unsigned NOT NULL default '0',  lastpost int unsigned NOT NULL default '0',  posts smallint unsigned NOT NULL default '0',  timezoneoffset varchar(4) NOT NULL default '',  emailnotification smallint NOT NULL default '0',  buddylist mediumtext NOT NULL,  ignorelist mediumtext NOT NULL,  pmfolders mediumtext NOT NULL,  receivepm smallint NOT NULL default '0',  emailonpm smallint NOT NULL default '0',  pmpopup smallint NOT NULL default '0',  avatarid smallint NOT NULL default '0',  avatarrevision int unsigned NOT NULL default '0',  options smallint NOT NULL default '15',  birthday date NOT NULL default '0000-00-00',  maxposts smallint NOT NULL default '-1',  startofweek smallint NOT NULL default '1',  ipaddress varchar(20) NOT NULL default '',  referrerid int unsigned NOT NULL default '0',  nosessionhash smallint NOT NULL default '0',  autorefresh smallint NOT NULL default '-1',  messagepopup tinyint NOT NULL default '0',  inforum smallint unsigned NOT NULL default '0',  ratenum smallint unsigned NOT NULL default '0',  ratetotal smallint unsigned NOT NULL default '0',  allowrate smallint unsigned NOT NULL default '1',  PRIMARY KEY  (userid),  KEY usergroupid (usergroupid),  KEY username (username),  KEY inforum (inforum)) ENGINE=MyISAM;
408
 
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,'0000-00-00',-1,1,'64.0.0.0',0,1,-1,0,0,4,19,1);
 
384
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));
 
385
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);
409
386
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
410
387
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
411
 
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      0000-00-00      -1      1       64.0.0.0        0       1       -1      0       0       4       19      1
 
388
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
412
389
DROP TABLE t1,t2;
413
390
CREATE TABLE t1 (a int primary key, b int, c int);
414
391
INSERT t1 VALUES (1,2,3);
418
395
a       b
419
396
1       4
420
397
DROP TABLE t1,t2;
421
 
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
398
CREATE table t1 (  `id` int NOT NULL auto_increment,  `name` varchar(50) NOT NULL default '',  PRIMARY KEY  (`id`)) AUTO_INCREMENT=3 ;
422
399
INSERT INTO t1 VALUES (1, 'aaaaa');
423
400
INSERT INTO t1 VALUES (3, 'aaaaa');
424
401
INSERT INTO t1 VALUES (2, 'eeeeeee');
458
435
html varchar(5) default NULL,
459
436
rin int default '0',
460
437
rout int default '0'
461
 
) ENGINE=MyISAM;
 
438
);
462
439
INSERT INTO t1 VALUES ('1',1,0);
463
440
SELECT DISTINCT html,SUM(rout)/(SUM(rin)+1) as 'prod' FROM t1 GROUP BY rin;
464
441
html    prod
581
558
y decimal(10,0) default NULL,
582
559
PRIMARY KEY  (ID),
583
560
KEY (y)
584
 
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 
561
);
585
562
INSERT INTO t1 VALUES
586
563
(1,'ba','-1'),
587
564
(2,'ba','1150'),
608
585
SELECT DISTINCT a,a FROM t1 WHERE b < 12 ORDER BY a;
609
586
a       a
610
587
DROP TABLE t1;
611
 
CREATE TABLE t1 (a CHAR(1));
612
 
INSERT INTO t1 VALUES('A'), (0);
613
 
SELECT a FROM t1 WHERE a=0;
614
 
a
615
 
A
616
 
0
617
 
SELECT DISTINCT a FROM t1 WHERE a=0;
618
 
a
619
 
A
620
 
0
621
 
DROP TABLE t1;
622
 
CREATE TABLE t1 (a DATE);
623
 
INSERT INTO t1 VALUES ('1972-07-29'), ('1972-02-06');
624
 
EXPLAIN SELECT (SELECT DISTINCT a FROM t1 WHERE a = '2002-08-03');
625
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
626
 
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
627
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    2       Using where
628
 
EXPLAIN SELECT (SELECT DISTINCT ADDDATE(a,1) FROM t1
629
 
WHERE ADDDATE(a,1) = '2002-08-03');
630
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
631
 
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
632
 
2       SUBQUERY        t1      ALL     NULL    NULL    NULL    NULL    2       Using where
633
 
CREATE TABLE t2 (a CHAR(5) CHARACTER SET latin1 COLLATE latin1_general_ci);
634
 
INSERT INTO t2 VALUES (0xf6);
635
 
INSERT INTO t2 VALUES ('oe');
636
 
SELECT COUNT(*) FROM (SELECT DISTINCT a FROM t2) dt;
637
 
COUNT(*)
638
 
2
639
 
SELECT COUNT(*) FROM 
640
 
(SELECT DISTINCT a FROM t2 WHERE a='oe' COLLATE latin1_german2_ci) dt;
641
 
COUNT(*)
642
 
2
643
 
DROP TABLE t1, t2;
644
588
CREATE TABLE t1 (a INT, UNIQUE (a));
645
589
INSERT INTO t1 VALUES (4),(null),(2),(1),(null),(3);
646
590
EXPLAIN SELECT DISTINCT a FROM t1;
678
622
1       1       3
679
623
DROP TABLE t1;
680
624
End of 5.0 tests
681
 
CREATE TABLE t1(a INT, b INT, c INT, d INT, e INT,
 
625
CREATE TABLE t1(a INT, b INT, c INT, d INT DEFAULT 0, e INT DEFAULT 0,
682
626
PRIMARY KEY(a,b,c,d,e),
683
627
KEY(a,b,d,c)
684
628
);