Subject Order of execution of SQL statements in FB
Author Tom Conlon
Hi,

Can anyone confirm if FB follows this SQL order of execution:
(see http://www.bennadel.com/blog/70-SQL-Query-Order-of-Operations.htm
and Celko 'SQL for Smarties')

1. FROM clause (***includes JOIN + ON statements***)
2. WHERE clause (select expressions not referencible yet)
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause

This seems to have very significant implications for a complex query
that has joins - whether to _consciously_ put conditions as part of
the ON statement rather than the WHERE statement.

From bennadel:
"...Since this clause executes first, it is our first opportunity to
narrow down possible record set sizes. This is why I put as many of my
ON rules (for joins) as possible in this area as opposed to in the
WHERE clause:

e.g.
FROM contact c
INNER JOIN display_status d ON (c.display_status_id = d.id AND
d.is_active = 1 AND d.is_viewable = 1)

This way, by the time we get to the WHERE clause, we will have already
excluded rows where is_active and is_viewable do not equal 1"


Tom