ORDER BY in a compound SELECT will first match against the left-most SELECT.

If there is no match there, it begins working its way to the right. (CVS 4621)

FossilOrigin-Name: 56063ec84b130bcdb0e90bc76fabca394d0d867f
This commit is contained in:
drh
2007-12-13 03:45:07 +00:00
parent 9a99334d54
commit 1e281291fb
6 changed files with 93 additions and 41 deletions
+17 -1
View File
@@ -150,7 +150,13 @@ do_test null-5.1 {
} {{} 0 1}
# A UNION to two queries should treat NULL values
# as distinct
# as distinct.
#
# (Later:) We also take this opportunity to test the ability
# of an ORDER BY clause to bind to either SELECT of a UNION.
# The left-most SELECT is preferred. In standard SQL, only
# the left SELECT can be used. The ability to match an ORDER
# BY term to the right SELECT is an SQLite extension.
#
ifcapable compound {
do_test null-6.1 {
@@ -173,6 +179,16 @@ ifcapable compound {
select b from t1 union select c from t1 order by main.t1.b;
}
} {{} 0 1}
do_test null-6.5 {
execsql {
select b from t1 union select c from t1 order by t1.a;
}
} {{} 0 1}
do_test null-6.6 {
execsql {
select b from t1 union select c from t1 order by main.t1.a;
}
} {{} 0 1}
} ;# ifcapable compound
# The UNIQUE constraint only applies to non-null values
+6 -3
View File
@@ -12,7 +12,7 @@
# focus of this file is testing UNION, INTERSECT and EXCEPT operators
# in SELECT statements.
#
# $Id: select4.test,v 1.22 2007/12/10 18:51:48 danielk1977 Exp $
# $Id: select4.test,v 1.23 2007/12/13 03:45:08 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -210,12 +210,15 @@ do_test select4-4.1.1 {
do_test select4-4.1.2 {
execsql {
SELECT DISTINCT log FROM t1 UNION ALL SELECT 6
SELECT DISTINCT log FROM t1
UNION ALL
SELECT 6
INTERSECT
SELECT n FROM t1 WHERE log=3
ORDER BY log;
ORDER BY t1.log;
}
} {5 6}
do_test select4-4.1.3 {
execsql {
CREATE TABLE t2 AS