Skip to content
Theory · Aggregates and GROUP BY · lesson 6 of 10

The order a query runs in

A query can now have seven parts: SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT. They are always written in this order. But the database runs them in a different one. In chapter 2 that explained why an alias from SELECT (price * 2 AS double_price) works in ORDER BY but gives a "column does not exist" error in WHERE.

In this lesson

  • Written order and run order
  • A query on the conveyor
  • Aliases and the order
  • Common mistake
  • Key points