SELECT DISTINCTROW/ORDER BY on multiple tables
am 02.08.2002 16:22:32 von Stephen T CuppettDescription:
When using an ORDER BY clause on a multiple table SELECT DISTINCT=
ROW,
it appears that the ORDER BY column is taken into account for distincti=
on
even when it isn't a returned column in hte resultset. This does not
appear to be the case when you perform the select from one table.
How-To-Repeat:
# ----------------------------
# Creating tables for the test
# ----------------------------
CREATE TABLE table1 (email varchar(50), infoID BIGINT, dateentered
DATETIME);
CREATE TABLE table2 (infoID BIGINT, shipcode varchar(10));
# -----------------
# Populating table1
# -----------------
INSERT INTO table1(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 table2(infoID, shipcode) VALUES
(1, 'Z001'),
(2, 'R002');
# ------------------------------
# Reading out correct statements
# ------------------------------
SELECT DISTINCTROW email, shipcode FROM table1, table2 WHERE
table1.infoID=3Dtable2.infoID;
SELECT DISTINCTROW email FROM table1 ORDER BY dateentered DESC;
# -----------------------------
# Reading out erratic statement
# -----------------------------
SELECT DISTINCTROW email, shipcode FROM table1, table2 WHERE
table1.infoID=3Dtable2.infoID
ORDER BY dateentered DESC;
# -----------
# Cleaning up
# -----------
DROP TABLE table1;
DROP TABLE table2;?
Fix:
Use unordered data
Submitter-Id: stcuppet@us.ibm.com
Originator: Stephen Cuppett
Organization: IBM, eServer zSeries development
MySQL support: none
Synopsis:
Severity: serious
Priority: medium
Category: mysql
Class: sw-bug
Release: mysql-3.23.51 (Official MySQL RPM)
Server: /usr/bin/mysqladmin Ver 8.23 Distrib 3.23.51, for pc-linux-gnu=
on
i686
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,=
and you are welcome to modify and redistribute it under the GPL license=
Server version 3.23.51-Max
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 2 hours 29 min 51 sec
Threads: 1 Questions: 1 Slow queries: 0 Opens: 6 Flush tables: 1 O=
pen
tables: 0 Queries per second avg: 0.000
Environment:
System: Linux cuppett-udp4298546uds.endicott.ibm.com 2.4.18-3 #1 Thu Ap=
r 18
07:37:53 EDT 2002 i686 unknown
Architecture: i686
Some paths: /usr/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc
/usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-112)
Compilation info: CC=3D'gcc' CFLAGS=3D'-O6 -fno-omit-frame-pointer -mp=
entium'
CXX=3D'gcc' CXXFLAGS=3D'-O6 -fno-omit-frame-pointer
-felide-constructors -fno-exceptions -fno-rtti -mpentium' LDFLAGS=3D''=
LIBC:
lrwxrwxrwx 1 root root 13 Jul 29 07:00 /lib/libc.so.6 =
->
libc-2.2.5.so
-rwxr-xr-x 1 root root 1260480 Jul 9 11:58 /lib/libc-2.2.5=
..so
-rw-r--r-- 1 root root 2312370 Jul 9 11:25 /usr/lib/libc.a=
-rw-r--r-- 1 root root 178 Jul 9 11:19 /usr/lib/libc.s=
o
Configure command: ./configure --disable-shared --with-mysqld-ldflags
=3D-all-static --with-client-ldflags=3D-all-static
--with-other-libc=3D/usr/local/mysql-glibc --without-berkeley-db
--without-innodb --enable-assembler --enable-local-infile
--with-mysqld-user=3Dmysql --with-unix-socket-path=3D/var/lib/mysql/mys=
ql.sock
--prefix=3D/ --with-extra-charsets=3Dcomplex --exec-prefix=3D/usr
--libexecdir=3D/usr/sbin --sysconfdir=3D/etc --datadir=3D/usr/share
--localstatedir=3D/var/lib/mysql --infodir=3D/usr/info
--includedir=3D/usr/include --mandir=3D/usr/man '--with-comment=3DOffic=
ial MySQL
RPM' CC=3Dgcc 'CFLAGS=3D-O6 -fno-omit-frame-pointer -mpentium' 'CXXFLAG=
S=3D-O6
-fno-omit-frame-pointer -felide-constructors
-fno-exceptions -fno-rtti -mpentium' CXX=3Dgcc
=
------------------------------------------------------------ ---------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail bugs-thread12273@lists.mysql.com
To unsubscribe, e-mail