Exceptions to flattening

A subquery introduced with in, any, or exists cannot be flattened if one of the following is true:

If the subquery computes a scalar aggregate, materialization rather than flattening is used.

See “Materializing subquery results”.