Showing posts with label sql statement execution. Show all posts
Showing posts with label sql statement execution. Show all posts

Wednesday, December 2, 2015

SQL Statement Execution Flow

Suppose we have a following SQL statement.


select  employee_id, first_name
from hr.employees
where employee_id = 120
order by first_name

This statement will be validated in the following order


  • Table list in the FROM clause
  • Order BY clause columns, expressions
  • Where clause conditions
  • Finally Select list

Similarly for the following SQL

select employee_id, first_name, sum(salary)
 from hr.emp_data
where salary <> 0
group by employee_id, first_name
having sum(salary) > 0
order by employee_id, first_name

      • Table list in the FROM clause
      • Order BY clause columns, expressions
      • Having Clause
      • Group By Clause
      • Where clause conditions
      • Finally Select list