SQLite User Forum

Unexpected Result by ORDER BY
Login

Unexpected Result by ORDER BY

(1) By Jinsheng Ba (bajinsheng) on 2022-06-07 07:35:39 [source]

The second SELECT with the ORDER BY clause returns 1, while the first SELECT returns NULL.

CREATE TABLE t0(c0);
CREATE VIEW v0(c0) AS SELECT t0.c0 FROM t0;
CREATE TABLE t1 (c0);
INSERT INTO t0 VALUES ('1');
SELECT SUM(count) FROM (SELECT 1 as count FROM t1 INNER JOIN v0 ON t1.c0 RIGHT OUTER JOIN t0 ON t1.c0 ORDER BY t1.c0);
-- Null
SELECT SUM(count) FROM (SELECT 1 as count FROM t1 INNER JOIN v0 ON t1.c0 RIGHT OUTER JOIN t0 ON t1.c0);
-- 1

Environment:

Version: 3.39.0

Commit ID: 318543a9

OS: Ubuntu 20.04

Configuration Options: ./configure --enable-all

Compiler: gcc-9

Client: CLI

(2) By Richard Hipp (drh) on 2022-06-07 16:50:16 in reply to 1 [link] [source]

Should now be working on trunk, after check-in 3f45007d544e5f78.

(3) By Jinsheng Ba (bajinsheng) on 2022-06-08 05:43:54 in reply to 2 [link] [source]

Thanks!