SQLite Forum

Possible bug: Unexpected result using correlated aggregate subquery
Login
SQLite computes the same answer as PostgreSQL here.

To be clear, I had to modify the code slightly to conform to PG syntax:

  *  Add a LIMIT 1 to the subquery.  The LIMIT 1 is implied by SQLite, but
     must be explicit in PG (also in MySQL and SQL Server).

  *  Change group_concat() into string_agg().

I end up with this:

> ~~~
CREATE TABLE t1(a varchar);
CREATE TABLE t2(b varchar);
INSERT INTO t1 VALUES(1);
INSERT INTO t2 VALUES(2),(3);
SELECT (SELECT string_agg(a,',') FROM t2 LIMIT 1) FROM t1;
~~~

To which PG gives an answer of just "1", same as SQLite.