subqueries execution order

R

rocco

Hello,
can someone make cleare in which order the subqueries in a SQL statement are
executed?
It seems this statment
SELECT CONTACT1.ID, CONTACT1.VISIT
FROM (SELECT ID, VISIT FROM CONTACT WHERE VISIT NOT LIKE 'c*') AS CONTACT1
WHERE CINT(CONTACT1.VISIT)>12

can't work because the WHERE clause of the main query is executed BEFORE the
WHERE clause in the subquery. This sounds odd to me because if the subquery
wont run first, there shouldn't be any table, and so any row, to evaluate by
the WHERE clause of the main query.
So, just to have things more clear in my mind, can you please give a short
hint on the order in which subqueries are executed?
Thank you all very very much,
Rocco
 
R

Rick Brandt

rocco said:
Hello,
can someone make cleare in which order the subqueries in a SQL
statement are executed?
It seems this statment
SELECT CONTACT1.ID, CONTACT1.VISIT
FROM (SELECT ID, VISIT FROM CONTACT WHERE VISIT NOT LIKE 'c*') AS
CONTACT1 WHERE CINT(CONTACT1.VISIT)>12

can't work because the WHERE clause of the main query is executed
BEFORE the WHERE clause in the subquery. This sounds odd to me
because if the subquery wont run first, there shouldn't be any table,
and so any row, to evaluate by the WHERE clause of the main query.
So, just to have things more clear in my mind, can you please give a
short hint on the order in which subqueries are executed?
Thank you all very very much,
Rocco

Database engines have very complex structures in their query optimizers.
I'm not sure that there is any reliable way to predict how the optimizer
will decide to process the query. I'm not even sure that the same query
will always be processed the same way if run on two different occassions.
 
R

rocco

oh!...interesting...and a little bit scaring!!

Rick Brandt said:
Database engines have very complex structures in their query optimizers.
I'm not sure that there is any reliable way to predict how the optimizer
will decide to process the query. I'm not even sure that the same query
will always be processed the same way if run on two different occassions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top