Given theses tables:
create temporary table a(pid integer, cid integer);
create temporary table b(id integer, code varchar);
This works but returns wrong results:
select pid
from a
where cid in (select cid from b where code like 'AE%')
I just had a query like that where I use the wrong field, and it surprised me that that query even works. Doesn’t a query like this just return all the rows from table a ?
Do you have any example of a query written like this that would be useful ?
Maybe I’m missing something.
You regulary need fields from the outer query in the where clause of the inner query:
or
We can also construct examples where the outer fields are (kind of) useful in the select clause:
Therefore, access to the fields of the outer query is absolutely necessary.