Oracle 19c SQL

  1. Home
  2. Docs
  3. Oracle 19c SQL
  4. 2 Parts of Oracle SQL Query
  5. 2.8 Query Execution Order

2.8 Query Execution Order

Oracle processes SQL queries based on the following order.

  • FROM
  • WHERE
  • GROUP BY
  • SELECT
  • HAVING
  • ORDER BY

When you have Joins

You specify multiple tables in the query FROM clause and join condition in WHERE clause.

  • A join, is evaluated first, whether the join is specified in the FROM clause (ANSI join) or with WHERE clause predicates
  • WHERE Clause other filter conditions if any
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause

When you have Hierarchical query

  • A join, if present, is evaluated first
  • START WITH and CONNECT BY conditions are evaluated
  • WHERE Clause filter conditions other than join condition if any
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause

If you are working with hierarchical data and using CONNECT BY, then do not specify either ORDER BY or GROUP BY, because they will destroy the hierarchical order of the CONNECT BY results. If you want to order rows of siblings of the same parent, then use the ORDER SIBLINGS BY clause.

When you have Pseudo Columns

  • A join, if present, is evaluated first
  • START WITH and CONNECT BY conditions are evaluated
  • WHERE Clause filter conditions other than join condition if any
  • GROUP BY Clause
  • HAVING Clause
  • Pseudo Columns are applied
  • ORDER BY Clause

NOTE

Pseudo columns no matter where they are present are evaluated to the last for the sake of presentation. You must be very careful if you use pseudo columns in filter condition like WHERE or HAVING. Though WHERE/HAVING clauses have higher precedence than pseudo columns, the filter that includes pseudo columns have to wait for the pseudo column value and hence evaluated at last.

Was this article helpful to you? Yes No

How can we help?