query
Scalar subquery cardinality errors
PostgreSQL rejects a scalar subquery returning multiple rows with SQLSTATE 21000. SQLite instead uses the first row; ORDER BY makes this comparison deterministic.
Formal Syntax & Structure
sql syntaxsql
(SELECT value FROM source)Working Example
Example Snippetsql
CREATE TABLE a(id int primary key,k int); CREATE TABLE b(k int); INSERT INTO a VALUES (1,10),(2,20),(3,NULL); INSERT INTO b VALUES (10),(10),(NULL);SELECT (SELECT k FROM a ORDER BY id);