We use SELECT statement to retrieve data from SQL.
Generally we type T-SQL clauses in below order:
SELECT
FROM
WHERE
GROUP BY
HAVING
ORDER BY
But the logical query processing order is different.
FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY
For example -
If we want return all employees from deptno 30.
SELECT ename,sal FROM emp WHERE deptno=30 ORDER BY ename
When it goes to SQL, it executes as below
FROM emp
WHERE deptno=30
SELECT ename,sal
ORDER BY ename
Each execution phase operates on one or more tables (if JOIN involved) as inputs and returns a virtual table as output. The output table of one phase is considered the input to the next phase.