Microsoft currently permits this syntax.
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT *
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
HAVING count(*) > 1
);
Notice that there is no GROUP BY
in the EXISTS
clause, is that valid ANSI SQL. Or is it merely exposing an implementation detail.
For reference, this same syntax isn't permitted in PostgreSQL.
ERROR: column "t.x" must appear in the GROUP BY clause or be used in an aggregate function
But this syntax is permitted..
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT 1 -- This changed from the first query
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
HAVING count(*) > 1
);
And this syntax is permitted.
SELECT *
FROM ( VALUES (1) ) AS g(x)
WHERE EXISTS (
SELECT *
FROM ( VALUES (1),(1) )
AS t(x)
WHERE g.x = t.x
GROUP BY t.x -- This changed from the first query
HAVING count(*) > 1
);
Question arises from a conversation with @ErikE in chat