SQLite Forum

Possible bug: Unexpected result using correlated aggregate subquery
Login
I mean you have to admit that it does seem a little weird that an aggregate function in the sub-query makes the outer query an aggregate. That is a little unexpected.

SQLite version 3.36.0 2021-06-18 18:36:39
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> create table x (a);
sqlite> create table y (b);
sqlite> insert into x values (1), (2);
sqlite> insert into y values (7), (8), (9);
sqlite> select (select group_concat(y.b) from y) from x; --returns 2 rows
7,8,9
7,8,9
sqlite> select (select group_concat(5) from y) from x; --returns 2 rows
5,5,5
5,5,5
sqlite> select (select group_concat(x.a) from y) from x; --now only returns 1 row
1,2

sqlite> select (select count(*) from (select group_concat(y.b) from y)) from x;
1
1
sqlite> select (select count(*) from (select group_concat(5) from y)) from x;
1
1
sqlite> select (select count(*) from (select group_concat(x.a) from y)) from x;
3
sqlite>