SQL 101

Some key thought about how to get what you want out of your SQL query search!

First things first, get your order of operations correct! The order is as follows:

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY

SELECT

This tells your search what you want it to return. A '*' returns everything, "Header" will return the columns underneath the header. If you want to return multiple columns then just write

SELECT "Header1"

,"Header2"

Another important way to use this is to use  this is to look at SELECT DISTINCT which will return all of the unique values in the row that you have selected.

FROM

This shows where SQL queries from. In a file explorer this would look like the file path but SQL is used to search a database so the order will go "Database_Object"."Schema"."Table"

WHERE

This is a where of filtering out your data. For example selecting only certain values within columns.  There are a number of operators for this part of the query including: =, <> or !=, >, <, >=, <=, BETWEEN, IN and LIKE. You can also link these by AND or OR depending on what values you would like to return.

GROUP BY

Will allow you to aggregate your columns to a specific dimension

HAVING

Allows you to order to things within certain boundaries. It is an aggregated filter so it could include things such as HAVING SUM("Header1")>1000 or HAVING AVG("Header2")<150

ORDER BY

This allows you to order your data (how surprising!). You can select to have any of your columns in either ascending (ASC) or descending (DESC) order.

Author:
Cammy Phillips
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