Have you failed a job interview?
Send us your job interview questions and get correct answers.

What is the processing order of logical parts of the following query?

SELECT ClientId, SUM(t2.Amount) total FROM cliens t1 JOIN orders t2 ON t1.ClientId = t2.ClientId WHERE ClientName Like 'John%' GROUP BY ClientId HAVING t2.Amount > 100 ORDER BY total DESC LIMIT 1

Experience Level: Medior
Tags: DatabasesSQL


The database engine processes the query in the following order:

  1. FROM and JOINs - determines and filters the rows using criteria in ON clause
  2. WHERE - applies additional filters on the rows
  3. GROUP BY - groups the rows into groups by column values
  4. HAVING - filters groups
  5. ORDER BY - orders the remaining rows/groups
  6. LIMIT - filters on the remaining rows/groups
  7. SELECT - returns the selected columnd


No Comments Yet.
Be the first to tell us what you think.