• Kenneth.Fisher (1/19/2014)


    Honestly, while I agree that knowing the execution order is important, the idea that all queries can exclude entries in the WHERE clause makes me nervious as *&@#. If you are doing INNER JOINs then no problem, it will have the same effect. I just don't see how you can manage restrictions on a query with an OUTER or CROSS JOIN without a WHERE clause.

    You should not be nervous. There is no magic in the query syntax. This is the problem I see with the article: it seems some sort of documentary on the strange habits of SQL queries.

    Talking about your example, you have three concepts:

    1. you are interested in professors with courses (a conditional on the year)

    2. but you want also the ones without courses (an Outer, because that is the only tool you have to "revive" a set of records previously excluded by a conditional)

    3. but all the results should have tenure (another conditional)

    1 and 2 are to be executed one after the other: you firstly select, and then pick up also the ones that where excluded. So 1 must go in the ON.

    Where should 3 go? Well, it depends on your requirement:

    If you want a list of ALL the professors, it must go before the OUTER, so in the ON clause.

    If, as is the case, you want only professors with Tenure, you must be sure that the clause is in the WHERE.

    Think it this way:

    1. ON is a tool to pick record pairs in a cartesian product. So it's a way to discard records.

    2. Outer is a way to "revive" discarded records from one or two tables.

    3. After the Outer, the result set will be composed by two sub sets: the paired rows produced by the ON clause, and the unpaired, revived rows picked up by the OUTER.

    4. The WHERE will be applied to everything, even the unpaired rows.

    So you NEED both tools, and you decide where a conditional has to be based on if it must be applied only to paired rows or also to unpaired ones.

    Only a problem of execution order, as I said.

    Edit: fixing typos