Today I’m going to discuss about the Logical Query
Processing in T-SQL
Logical Query Processing: The conceptual interpretation of
the query that explain what the correct result of the query is
Physical Query Processing: Processing of the query by
database engine. Produce the result defined by logical query processing.
Following are the Main Query Clauses in the order that you
are supposed to type (known as “keyed-in-order”)
- SELECT
- FROM
- WHERE
- GROUP BY
- HAVING
- ORDER BY
But the Logical Query Processing order, which is the
Conceptual interpretation order, is different
- FROM
- WHERE
- GROUP BY
- HAVING
- SELECT
- ORDER BY
Because of this logical order you won’t get expected result for
below sample query,
SELECT Name , YEAR(Joindate) AS JoinDate
FROM dbo.Emplyees
WHERE JoinDate > 2000
This should be,
SELECT Name , YEAR(Joindate) AS JoinDate
FROM dbo.Emplyees
WHERE YEAR(Joindate) > 2000