Is one row on correct for 'SELECT (SELECT SUM(t.val)) FROM mytable t'

38 views Asked by At

Postgres and some online SQL engines return just one row for the SELECT:

CREATE TABLE mytable(val INTEGER);
INSERT INTO mytable VALUES (1), (2), (3), (NULL);

SELECT (SELECT SUM(t.val)) FROM mytable t;

The result is:

6

Does it correspond to the SQL spec? Which section on the spec do I need?

Should the subquery be invoked for every table record? Why the result is not several rows like:

1
2
3
null
0

There are 0 answers