Multiple join involving subquery containing TOTAL function produces wrong result
(1.3) By Zhaokun Xiang (silva9988) on 2025-06-09 09:33:46 edited from 1.2 [source]
Hi, SQLite developers,
Please see the below test cases, I meet an unexpected multiple join result.(Here I just refine and reformat my bug report for some proposes.) The version I use is SQLite version 3.49.1 2025-02-18 13:38:58.
CREATE TABLE t0 (c0 INT);
CREATE TABLE t1 (c0 INT);
INSERT INTO t1 VALUES (1);
INSERT INTO t0 VALUES (0);
SELECT (t0.c0 is null), t1.c0
FROM (SELECT TOTAL(0) OVER () AS col_0 FROM t0) as subQuery
LEFT JOIN t0 ON ((CASE 1
WHEN 1 THEN subQuery.col_0
END) LIKE (((((subQuery.col_0))))))
INNER JOIN t1 ON ((subQuery.col_0) == (false));
-- 1, 1 Wrong result
-- Expected result: 0, 1
(2) By Dan Kennedy (dan) on 2025-04-10 15:05:39 in reply to 1.2 [link] [source]
This one is a real problem - thanks for posting! Should now be fixed here:
https://sqlite.org/src/info/979f384a93
Dan.
(3) By Zhaokun Xiang (silva9988) on 2025-04-11 04:02:12 in reply to 2 [link] [source]
Thanks for your feedback and effort!