Skip to content

Correlated Scalar Subquery Returns NULL After First Row #5151

@LeMikaelF

Description

@LeMikaelF

Description

Correlated scalar subqueries return correct value for first row, NULL for subsequent rows.

Reproducer

CREATE TABLE t1(id INTEGER PRIMARY KEY);
CREATE TABLE t2(id INTEGER PRIMARY KEY, val INT);
INSERT INTO t1 VALUES(1), (2), (3);
INSERT INTO t2 VALUES(1, 100), (2, 200), (3, 300);

SELECT id, (SELECT val FROM t2 WHERE t2.id = t1.id) AS subq FROM t1;
-- Turso:  1|100, 2|NULL, 3|NULL
-- SQLite: 1|100, 2|200,  3|300

This issue brought to you by Mikaël and Claude Code.

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions