> Here the aliases `c` do infringe. In the subquery, we don't really know
> which reference the `c` alias should resolve to. We *could* here
assuming
> that the subquery is uncorrelated. Bu without this rule we really would
> not know that the subquery is correlated
Out of curiosity, Couldn't for this case assume that the second alias
overrides the first.
This might cause some hard to spot errors, though.
The issue really is for cases of correlated subqueries (where the subquery
refers to the outer query). So imagine a query such as:
select ...
from Salesperson s
where exists (
select count(*)
from Sale s2
where s.id = s2.salesperson.id ...
group by s2.salesperson.id
having count(*) > :sales
)
So here the predicate `s.id = s2.salesperson.id` defines a correlation
beween hthe queries. If we allowed the "alias overriding", it is quite
possible for the user to (mistakenly) write this query as:
select ...
from Salesperson s
where exists (
select count(*)
from Sale s
where s.id = s.salesperson.id ...
group by s.salesperson.id
having count(*) > :sales
)
Which validates fine, but is not *really* what they meant and would not
return what they are looking for.