Subject Re: [IBO] Order of Execution
Author Geoff Worboys
> Don't know if this is a IB or IBO question, but...

It is an IB/FB question, but it just so happens that I was reading
about some of this stuff recently...


> If I have a inline SELECT embedded within another SELECT, which
> SELECT is executed first?

It depends on where the inline select is embedded and what type
of embedding it is. The documentation (Embedded SQL Guide) only
discusses subqueries inside the WHERE clause, and it says:

"Because a subquery is a search condition, it is usually evaluated
before its parent query, which then uses the result to determine
whether or not a row qualifies for retrieval. The only exception is
the correlated subquery, where the parent query provides values for
the subquery to evaluate. For more information about correlated
subqueries, see “Correlated subqueries” on page 163."


> If the inline SELECT is executed last, then I could use the
> results of the outer SELECT as inputs into a inline selectable SP.

By this I presume you are talking about selects inline in the field
list. And the answer is yes you can.

eg:
SELECT A.*,
(SELECT X FROM PROC(A.ID)) AS TEST
FROM A

is really equivalent to the non procedure form of the same thing:
SELECT A.*,
(SELECT X FROM B WHERE B.ID=A.ID) AS TEST
FROM A


It is not so much that the inline select is executed last, as the
fact that it is executed for every row of the outer select.


--
Geoff Worboys
Telesis Computing