The SQL Hierarchy

When Coding in SQL there is a hierarchy that's important to remember.

This may seem backwards in some instances SQL will only read in a specific order.

The order these tools work in is

  • Select
  • From
  • Where
  • Group by
  • Having
  • Order by

Select - this is the function the tells SQL which fields you want to see (told you it was backwards) make sure each of the fields that you want to output are separated by a comma

From - This tells SQL which table the data will be stored in, it is often best practice to put the entire file path to make sure there is no confusion

Where  - This tells SQL which filters you want to apply to that fields, eg - Where Contains(Name, "J")

Group by - if we have some sort of aggregation this will tell SQL what to group the aggregation by

eg: Select Name, Sum(Sales)

Group by Name

Having - this is very similar to the where function - however is primarily for those aggregation functions

Finally order By - tells SQL how to sequence the results

Author:
Myles Stevenson
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab