mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
b388eb004d
bmove_allign -> bmove_align Added OLAP function ROLLUP Split mysql_fix_privilege_tables to a script and a .sql data file Added new (MEMROOT*) functions to avoid calling current_thd() when creating some common objects. Added table_alias_charset, for easier --lower-case-table-name handling Better SQL_MODE handling (Setting complex options also sets sub options) New (faster) assembler string functions for x86 BitKeeper/etc/ignore: added libmysqld/sql_state.c client/mysql.cc: Added SQLSTATE to error messages Added new function put_error() to be able to clean up some old code. client/mysqltest.c: Write ERROR SQLSTATE for all errors dbug/dbug.c: Portability fixes include/m_string.h: Rename bmove_allign as bmove_align include/mysql.h: Added SQLSTATE (for embedded version) include/mysql_com.h: Send correct SQLSTATE for the error to the client libmysql/libmysql.c: Changed default error state to HY000 Applied code cleanup patch libmysqld/Makefile.am: Added sql_state.cc libmysqld/libmysqld.c: Added sqlstate mysql-test/r/analyse.result: Updated results mysql-test/r/ansi.result: Updated results mysql-test/r/auto_increment.result: Updated results mysql-test/r/bdb-deadlock.result: Updated results mysql-test/r/bdb.result: Updated results mysql-test/r/comments.result: Updated results mysql-test/r/create.result: Updated results mysql-test/r/ctype_collate.result: Updated results mysql-test/r/delayed.result: Updated results mysql-test/r/delete.result: Updated results mysql-test/r/derived.result: Updated results mysql-test/r/distinct.result: Updated results mysql-test/r/drop.result: Updated results mysql-test/r/err000001.result: Updated results mysql-test/r/explain.result: Updated results mysql-test/r/flush.result: Updated results mysql-test/r/fulltext.result: Updated results mysql-test/r/func_gconcat.result: Updated results mysql-test/r/func_system.result: Updated results mysql-test/r/grant_cache.result: Updated results mysql-test/r/group_by.result: Updated results mysql-test/r/handler.result: Updated results mysql-test/r/heap.result: Updated results mysql-test/r/heap_btree.result: Updated results mysql-test/r/heap_hash.result: Updated results mysql-test/r/innodb.result: Updated results mysql-test/r/innodb_handler.result: Updated results mysql-test/r/insert_select.result: Updated results mysql-test/r/insert_update.result: Updated results mysql-test/r/join.result: Updated results mysql-test/r/join_outer.result: Updated results mysql-test/r/key.result: Updated results mysql-test/r/lock.result: Updated results mysql-test/r/lock_multi.result: Updated results mysql-test/r/merge.result: Updated results mysql-test/r/multi_update.result: Updated results mysql-test/r/myisam.result: Updated results mysql-test/r/null.result: Updated results mysql-test/r/olap.result: Updated results mysql-test/r/order_by.result: Updated results mysql-test/r/packet.result: Updated results mysql-test/r/query_cache.result: Updated results mysql-test/r/row.result: Updated results mysql-test/r/rpl000001.result: Updated results mysql-test/r/rpl000009.result: Updated results mysql-test/r/rpl_empty_master_crash.result: Updated results mysql-test/r/rpl_log.result: Updated results mysql-test/r/rpl_replicate_do.result: Updated results mysql-test/r/rpl_rotate_logs.result: Updated results mysql-test/r/select.result: Updated results mysql-test/r/select_safe.result: Updated results mysql-test/r/show_check.result: Updated results mysql-test/r/sql_mode.result: Updated results mysql-test/r/subselect.result: Updated results mysql-test/r/temp_table.result: Updated results mysql-test/r/truncate.result: Updated results mysql-test/r/type_blob.result: Updated results mysql-test/r/type_decimal.result: Updated results mysql-test/r/type_float.result: Updated results mysql-test/r/type_ranges.result: Updated results mysql-test/r/union.result: Updated results mysql-test/r/update.result: Updated results mysql-test/r/user_var.result: Updated results mysql-test/r/varbinary.result: Updated results mysql-test/r/variables.result: Updated results mysql-test/t/ansi.test: Test of sql_mode mysql-test/t/derived.test: Updated results mysql-test/t/func_system.test: Make this independen of the MySQL server name mysql-test/t/lowercase_table.test: Cleanup mysql-test/t/olap.test: A lot of new tests mysql-test/t/sql_mode.test: More test for sql_mode mysql-test/t/subselect.test: Added a few new tests (to find a bug in the item_ref code) scripts/Makefile.am: Added mysql_fix_privilege_tables.sql scripts/mysql_fix_privilege_tables.sh: Totally new script. This bascily just pipes mysql_fix_privilege_tables.sql through 'mysql' to 'mysqld' sql/Makefile.am: Added sql_state.cc sql/item.cc: Extended Item_field::eq() to be able to better match GROUP BY fields on the command line. Needed for ROLLUP sql/item.h: Added function to be able to avoid calling current_thd() when doing new Item. sql/item_sum.cc: Moved copy_or_same() and some reset() functions from item_sum.h Needed to be able to access thd->mem_root. sql/item_sum.h: Moved some functions to item_sum.cc Added make_unique() for ROLLUP sql/item_uniq.h: Fixed return value sql/mysql_priv.h: Updated MODE flags sql/mysqld.cc: Added ANSI as it's own mode Moved charset_info variables here Cleaned up handler_count handling (for NT) Added table_alias_charset, for easier --lower-case-table-name handling sql/net_serv.cc: New comment sql/protocol.cc: Send SQLSTATE to client sql/set_var.cc: Better SQL_MODE handling (Setting complex options also sets sub options) sql/set_var.h: Better SQL_MODE handling sql/sql_base.cc: Make alias depend on --lower-case-table-names Make find_item_in_list also check database name sql/sql_cache.cc: Indentation cleanup sql/sql_list.h: Added safety assert Addes support of alloc without current_thd() sql/sql_prepare.cc: Update after prototype change sql/sql_select.cc: Added ROLLUP sql/sql_select.h: structures for rollup sql/sql_show.cc: Easier SQL_MODE handling sql/sql_string.cc: Move CHARSET_INFO to mysqld (to be together with all other global variables) sql/sql_string.h: Added function to be able to avoid calling current_thd() when doing new Item. sql/sql_table.cc: Simpler --lower-case-table-name handling sql/sql_union.cc: Update after prototype change sql/sql_yacc.yy: ROLLUP sql/unireg.h: bmove_allign ->bmove_align strings/Makefile.am: Fix to be able to compile str_test.c strings/ctype.c: Removed empty lines strings/str_test.c: Added test of bmove_align strings/strings-x86.s: Faster bmove_align, bmove_upp and strmake strings/strings.asm: move_allg
420 lines
15 KiB
Text
420 lines
15 KiB
Text
drop table if exists t1,t2,t3;
|
|
CREATE TABLE t1 (id int,facility char(20));
|
|
CREATE TABLE t2 (facility char(20));
|
|
INSERT INTO t1 VALUES (NULL,NULL);
|
|
INSERT INTO t1 VALUES (-1,'');
|
|
INSERT INTO t1 VALUES (0,'');
|
|
INSERT INTO t1 VALUES (1,'/L');
|
|
INSERT INTO t1 VALUES (2,'A01');
|
|
INSERT INTO t1 VALUES (3,'ANC');
|
|
INSERT INTO t1 VALUES (4,'F01');
|
|
INSERT INTO t1 VALUES (5,'FBX');
|
|
INSERT INTO t1 VALUES (6,'MT');
|
|
INSERT INTO t1 VALUES (7,'P');
|
|
INSERT INTO t1 VALUES (8,'RV');
|
|
INSERT INTO t1 VALUES (9,'SRV');
|
|
INSERT INTO t1 VALUES (10,'VMT');
|
|
INSERT INTO t2 SELECT DISTINCT FACILITY FROM t1;
|
|
select id from t1 group by id;
|
|
id
|
|
NULL
|
|
-1
|
|
0
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
10
|
|
select * from t1 order by id;
|
|
id facility
|
|
NULL NULL
|
|
-1
|
|
0
|
|
1 /L
|
|
2 A01
|
|
3 ANC
|
|
4 F01
|
|
5 FBX
|
|
6 MT
|
|
7 P
|
|
8 RV
|
|
9 SRV
|
|
10 VMT
|
|
select id-5,facility from t1 order by "id-5";
|
|
id-5 facility
|
|
NULL NULL
|
|
-6
|
|
-5
|
|
-4 /L
|
|
-3 A01
|
|
-2 ANC
|
|
-1 F01
|
|
0 FBX
|
|
1 MT
|
|
2 P
|
|
3 RV
|
|
4 SRV
|
|
5 VMT
|
|
select id,concat(facility) from t1 group by id ;
|
|
id concat(facility)
|
|
NULL NULL
|
|
-1
|
|
0
|
|
1 /L
|
|
2 A01
|
|
3 ANC
|
|
4 F01
|
|
5 FBX
|
|
6 MT
|
|
7 P
|
|
8 RV
|
|
9 SRV
|
|
10 VMT
|
|
select id+0 as a,max(id),concat(facility) as b from t1 group by a order by b desc,a;
|
|
a max(id) b
|
|
10 10 VMT
|
|
9 9 SRV
|
|
8 8 RV
|
|
7 7 P
|
|
6 6 MT
|
|
5 5 FBX
|
|
4 4 F01
|
|
3 3 ANC
|
|
2 2 A01
|
|
1 1 /L
|
|
-1 -1
|
|
0 0
|
|
NULL NULL NULL
|
|
select id >= 0 and id <= 5 as grp,count(*) from t1 group by grp;
|
|
grp count(*)
|
|
NULL 1
|
|
0 6
|
|
1 6
|
|
SELECT DISTINCT FACILITY FROM t1;
|
|
FACILITY
|
|
NULL
|
|
|
|
/L
|
|
A01
|
|
ANC
|
|
F01
|
|
FBX
|
|
MT
|
|
P
|
|
RV
|
|
SRV
|
|
VMT
|
|
SELECT FACILITY FROM t2;
|
|
FACILITY
|
|
NULL
|
|
|
|
/L
|
|
A01
|
|
ANC
|
|
F01
|
|
FBX
|
|
MT
|
|
P
|
|
RV
|
|
SRV
|
|
VMT
|
|
SELECT count(*) from t1,t2 where t1.facility=t2.facility;
|
|
count(*)
|
|
12
|
|
select count(facility) from t1;
|
|
count(facility)
|
|
12
|
|
select count(*) from t1;
|
|
count(*)
|
|
13
|
|
select count(*) from t1 where facility IS NULL;
|
|
count(*)
|
|
1
|
|
select count(*) from t1 where facility = NULL;
|
|
count(*)
|
|
0
|
|
select count(*) from t1 where facility IS NOT NULL;
|
|
count(*)
|
|
12
|
|
select count(*) from t1 where id IS NULL;
|
|
count(*)
|
|
1
|
|
select count(*) from t1 where id IS NOT NULL;
|
|
count(*)
|
|
12
|
|
drop table t1,t2;
|
|
CREATE TABLE t1 (UserId int(11) DEFAULT '0' NOT NULL);
|
|
INSERT INTO t1 VALUES (20);
|
|
INSERT INTO t1 VALUES (27);
|
|
SELECT UserId FROM t1 WHERE Userid=22;
|
|
UserId
|
|
SELECT UserId FROM t1 WHERE UserId=22 group by Userid;
|
|
UserId
|
|
SELECT DISTINCT UserId FROM t1 WHERE UserId=22 group by Userid;
|
|
UserId
|
|
SELECT DISTINCT UserId FROM t1 WHERE UserId=22;
|
|
UserId
|
|
drop table t1;
|
|
CREATE TABLE t1 (a int(10) unsigned not null primary key,b int(10) unsigned);
|
|
INSERT INTO t1 VALUES (1,1),(2,1);
|
|
CREATE TABLE t2 (a int(10) unsigned not null, key (A));
|
|
INSERT INTO t2 VALUES (1),(2);
|
|
CREATE TABLE t3 (a int(10) unsigned, key(A), b text);
|
|
INSERT INTO t3 VALUES (1,'1'),(2,'2');
|
|
SELECT DISTINCT t3.b FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
|
|
b
|
|
1
|
|
INSERT INTO t2 values (1),(2),(3);
|
|
INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2');
|
|
explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t3 index a a 5 NULL 6 Using index; Using temporary
|
|
1 SIMPLE t2 index a a 4 NULL 5 Using index; Distinct
|
|
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 Using where; Distinct
|
|
SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a;
|
|
a
|
|
1
|
|
create temporary table t4 select * from t3;
|
|
insert into t3 select * from t4;
|
|
insert into t4 select * from t3;
|
|
insert into t3 select * from t4;
|
|
insert into t4 select * from t3;
|
|
insert into t3 select * from t4;
|
|
insert into t4 select * from t3;
|
|
insert into t3 select * from t4;
|
|
explain select distinct t1.a from t1,t3 where t1.a=t3.a;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 2 Using index; Using temporary
|
|
1 SIMPLE t3 ref a a 5 test.t1.a 10 Using where; Using index; Distinct
|
|
select distinct t1.a from t1,t3 where t1.a=t3.a;
|
|
a
|
|
1
|
|
2
|
|
select distinct 1 from t1,t3 where t1.a=t3.a;
|
|
1
|
|
1
|
|
explain SELECT distinct t1.a from t1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
|
|
explain SELECT distinct t1.a from t1 order by a desc;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
|
|
explain SELECT t1.a from t1 group by a order by a desc;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
|
|
explain SELECT distinct t1.a from t1 order by a desc limit 1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
|
|
explain SELECT distinct a from t3 order by a desc limit 2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t3 index NULL a 5 NULL 204 Using index
|
|
explain SELECT distinct a,b from t3 order by a+1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
|
|
explain SELECT distinct a,b from t3 order by a limit 10;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t3 index NULL a 5 NULL 204 Using temporary
|
|
explain SELECT a,b from t3 group by a,b order by a+1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t3 ALL NULL NULL NULL NULL 204 Using temporary; Using filesort
|
|
drop table t1,t2,t3,t4;
|
|
CREATE TABLE t1 (name varchar(255));
|
|
INSERT INTO t1 VALUES ('aa'),('ab'),('ac'),('ad'),('ae');
|
|
SELECT DISTINCT * FROM t1 LIMIT 2;
|
|
name
|
|
aa
|
|
ab
|
|
SELECT DISTINCT name FROM t1 LIMIT 2;
|
|
name
|
|
aa
|
|
ab
|
|
SELECT DISTINCT 1 FROM t1 LIMIT 2;
|
|
1
|
|
1
|
|
drop table t1;
|
|
CREATE TABLE t1 (
|
|
ID int(11) NOT NULL auto_increment,
|
|
NAME varchar(75) DEFAULT '' NOT NULL,
|
|
LINK_ID int(11) DEFAULT '0' NOT NULL,
|
|
PRIMARY KEY (ID),
|
|
KEY NAME (NAME),
|
|
KEY LINK_ID (LINK_ID)
|
|
);
|
|
INSERT INTO t1 (ID, NAME, LINK_ID) VALUES (1,'Mike',0),(2,'Jack',0),(3,'Bill',0);
|
|
CREATE TABLE t2 (
|
|
ID int(11) NOT NULL auto_increment,
|
|
NAME varchar(150) DEFAULT '' NOT NULL,
|
|
PRIMARY KEY (ID),
|
|
KEY NAME (NAME)
|
|
);
|
|
SELECT DISTINCT
|
|
t2.id AS key_link_id,
|
|
t2.name AS link
|
|
FROM t1
|
|
LEFT JOIN t2 ON t1.link_id=t2.id
|
|
GROUP BY t1.id
|
|
ORDER BY link;
|
|
key_link_id link
|
|
NULL NULL
|
|
drop table t1,t2;
|
|
create table t1 (
|
|
id int not null,
|
|
name tinytext not null,
|
|
unique (id)
|
|
);
|
|
create table t2 (
|
|
id int not null,
|
|
idx int not null,
|
|
unique (id, idx)
|
|
);
|
|
create table t3 (
|
|
id int not null,
|
|
idx int not null,
|
|
unique (id, idx)
|
|
);
|
|
insert into t1 values (1,'yes'), (2,'no');
|
|
insert into t2 values (1,1);
|
|
insert into t3 values (1,1);
|
|
EXPLAIN
|
|
SELECT DISTINCT
|
|
t1.id
|
|
from
|
|
t1
|
|
straight_join
|
|
t2
|
|
straight_join
|
|
t3
|
|
straight_join
|
|
t1 as j_lj_t2 left join t2 as t2_lj
|
|
on j_lj_t2.id=t2_lj.id
|
|
straight_join
|
|
t1 as j_lj_t3 left join t3 as t3_lj
|
|
on j_lj_t3.id=t3_lj.id
|
|
WHERE
|
|
((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2))
|
|
AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2));
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index id id 4 NULL 2 Using index; Using temporary
|
|
1 SIMPLE t2 index id id 8 NULL 1 Using index; Distinct
|
|
1 SIMPLE t3 index id id 8 NULL 1 Using index; Distinct
|
|
1 SIMPLE j_lj_t2 index id id 4 NULL 2 Using where; Using index; Distinct
|
|
1 SIMPLE t2_lj index id id 8 NULL 1 Using where; Using index; Distinct
|
|
1 SIMPLE j_lj_t3 index id id 4 NULL 2 Using where; Using index; Distinct
|
|
1 SIMPLE t3_lj index id id 8 NULL 1 Using where; Using index; Distinct
|
|
SELECT DISTINCT
|
|
t1.id
|
|
from
|
|
t1
|
|
straight_join
|
|
t2
|
|
straight_join
|
|
t3
|
|
straight_join
|
|
t1 as j_lj_t2 left join t2 as t2_lj
|
|
on j_lj_t2.id=t2_lj.id
|
|
straight_join
|
|
t1 as j_lj_t3 left join t3 as t3_lj
|
|
on j_lj_t3.id=t3_lj.id
|
|
WHERE
|
|
((t1.id=j_lj_t2.id AND t2_lj.id IS NULL) OR (t1.id=t2.id AND t2.idx=2))
|
|
AND ((t1.id=j_lj_t3.id AND t3_lj.id IS NULL) OR (t1.id=t3.id AND t3.idx=2));
|
|
id
|
|
2
|
|
drop table t1,t2,t3;
|
|
create table t1 (a int not null, b int not null, t time);
|
|
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");
|
|
select a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
|
|
a sec_to_time(sum(time_to_sec(t)))
|
|
1 00:06:15
|
|
1 00:36:30
|
|
1 00:36:30
|
|
select distinct a,sec_to_time(sum(time_to_sec(t))) from t1 group by a,b;
|
|
a sec_to_time(sum(time_to_sec(t)))
|
|
1 00:06:15
|
|
1 00:36:30
|
|
create table t2 (a int not null primary key, b int);
|
|
insert into t2 values (1,1),(2,2),(3,3);
|
|
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;
|
|
a sec_to_time(sum(time_to_sec(t)))
|
|
1 00:06:15
|
|
1 00:36:30
|
|
1 00:36:30
|
|
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;
|
|
a sec_to_time(sum(time_to_sec(t)))
|
|
1 00:06:15
|
|
1 00:36:30
|
|
drop table t1,t2;
|
|
create table t1 (a int not null,b char(5), c text);
|
|
insert into t1 (a) values (1),(2),(3),(4),(1),(2),(3),(4);
|
|
select distinct a from t1 group by b,a having a > 2 order by a desc;
|
|
a
|
|
4
|
|
3
|
|
select distinct a,c from t1 group by b,c,a having a > 2 order by a desc;
|
|
a c
|
|
4 NULL
|
|
3 NULL
|
|
drop table t1;
|
|
create table t1 (a char(1), key(a)) type=myisam;
|
|
insert into t1 values('1'),('1');
|
|
select * from t1 where a >= '1';
|
|
a
|
|
1
|
|
1
|
|
select distinct a from t1 order by a desc;
|
|
a
|
|
1
|
|
select distinct a from t1 where a >= '1' order by a desc;
|
|
a
|
|
1
|
|
drop table t1;
|
|
CREATE TABLE t1 (email varchar(50), infoID BIGINT, dateentered DATETIME);
|
|
CREATE TABLE t2 (infoID BIGINT, shipcode varchar(10));
|
|
INSERT INTO t1 (email, infoID, dateentered) VALUES
|
|
('test1@testdomain.com', 1, '2002-07-30 22:56:38'),
|
|
('test1@testdomain.com', 1, '2002-07-27 22:58:16'),
|
|
('test2@testdomain.com', 1, '2002-06-19 15:22:19'),
|
|
('test2@testdomain.com', 2, '2002-06-18 14:23:47'),
|
|
('test3@testdomain.com', 1, '2002-05-19 22:17:32');
|
|
INSERT INTO t2(infoID, shipcode) VALUES
|
|
(1, 'Z001'),
|
|
(2, 'R002');
|
|
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID;
|
|
email shipcode
|
|
test1@testdomain.com Z001
|
|
test2@testdomain.com Z001
|
|
test3@testdomain.com Z001
|
|
test2@testdomain.com R002
|
|
SELECT DISTINCTROW email FROM t1 ORDER BY dateentered DESC;
|
|
email
|
|
test1@testdomain.com
|
|
test2@testdomain.com
|
|
test3@testdomain.com
|
|
SELECT DISTINCTROW email, shipcode FROM t1, t2 WHERE t1.infoID=t2.infoID ORDER BY dateentered DESC;
|
|
email shipcode
|
|
test1@testdomain.com Z001
|
|
test2@testdomain.com Z001
|
|
test2@testdomain.com R002
|
|
test3@testdomain.com Z001
|
|
drop table t1,t2;
|
|
CREATE TABLE t1 (privatemessageid int(10) unsigned NOT NULL auto_increment, folderid smallint(6) NOT NULL default '0', userid int(10) unsigned NOT NULL default '0', touserid int(10) unsigned NOT NULL default '0', fromuserid int(10) unsigned NOT NULL default '0', title varchar(250) NOT NULL default '', message mediumtext NOT NULL, dateline int(10) unsigned NOT NULL default '0', showsignature smallint(6) NOT NULL default '0', iconid smallint(5) unsigned NOT NULL default '0', messageread smallint(6) NOT NULL default '0', readtime int(10) unsigned NOT NULL default '0', receipt smallint(6) unsigned NOT NULL default '0', deleteprompt smallint(6) unsigned NOT NULL default '0', multiplerecipients smallint(6) unsigned NOT NULL default '0', PRIMARY KEY (privatemessageid), KEY userid (userid)) TYPE=MyISAM;
|
|
INSERT INTO t1 VALUES (128,0,33,33,8,':D','',996121863,1,0,2,996122850,2,0,0);
|
|
CREATE TABLE t2 (userid int(10) unsigned NOT NULL auto_increment, usergroupid smallint(5) 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(5) unsigned NOT NULL default '0', parentemail varchar(50) NOT NULL default '', coppauser smallint(6) 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(6) NOT NULL default '0', showemail smallint(6) NOT NULL default '0', invisible smallint(6) NOT NULL default '0', usertitle varchar(250) NOT NULL default '', customtitle smallint(6) NOT NULL default '0', joindate int(10) unsigned NOT NULL default '0', cookieuser smallint(6) NOT NULL default '0', daysprune smallint(6) NOT NULL default '0', lastvisit int(10) unsigned NOT NULL default '0', lastactivity int(10) unsigned NOT NULL default '0', lastpost int(10) unsigned NOT NULL default '0', posts smallint(5) unsigned NOT NULL default '0', timezoneoffset varchar(4) NOT NULL default '', emailnotification smallint(6) NOT NULL default '0', buddylist mediumtext NOT NULL, ignorelist mediumtext NOT NULL, pmfolders mediumtext NOT NULL, receivepm smallint(6) NOT NULL default '0', emailonpm smallint(6) NOT NULL default '0', pmpopup smallint(6) NOT NULL default '0', avatarid smallint(6) NOT NULL default '0', avatarrevision int(6) unsigned NOT NULL default '0', options smallint(6) NOT NULL default '15', birthday date NOT NULL default '0000-00-00', maxposts smallint(6) NOT NULL default '-1', startofweek smallint(6) NOT NULL default '1', ipaddress varchar(20) NOT NULL default '', referrerid int(10) unsigned NOT NULL default '0', nosessionhash smallint(6) NOT NULL default '0', autorefresh smallint(6) NOT NULL default '-1', messagepopup tinyint(2) NOT NULL default '0', inforum smallint(5) unsigned NOT NULL default '0', ratenum smallint(5) unsigned NOT NULL default '0', ratetotal smallint(5) unsigned NOT NULL default '0', allowrate smallint(5) unsigned NOT NULL default '1', PRIMARY KEY (userid), KEY usergroupid (usergroupid), KEY username (username), KEY inforum (inforum)) TYPE=MyISAM;
|
|
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);
|
|
SELECT DISTINCT t1.*, t2.* FROM t1 LEFT JOIN t2 ON (t2.userid = t1.touserid);
|
|
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
|
|
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
|
|
DROP TABLE t1,t2;
|
|
CREATE TABLE t1 (a int primary key, b int, c int);
|
|
INSERT t1 VALUES (1,2,3);
|
|
CREATE TABLE t2 (a int primary key, b int, c int);
|
|
INSERT t2 VALUES (3,4,5);
|
|
SELECT DISTINCT t1.a, t2.b FROM t1, t2 WHERE t1.a=1 ORDER BY t2.c;
|
|
a b
|
|
1 4
|
|
DROP TABLE t1,t2;
|