Structured Query Language (SQL) is one of the most important tools for working with data. If you’re just starting out, don’t worry — SQL is much easier than it looks. By learning a few core commands, you can already ask powerful questions from your data.
Let’s break down the essentials using a simple framework.
1. SELECT – What do you want to see?
The SELECT
statement tells SQL which columns you want from a table.
SELECT
OrderID, CustomerName
This means: Show me the OrderID
and CustomerName
columns.
2. FROM – Where is the data coming from?
The FROM
clause tells SQL which table to look in.
SELECT
OrderID, CustomerNameFROM
Orders
Now SQL knows to find those columns inside the Orders table.
3. WHERE – Pick rows conditionally
Use WHERE
to filter your results.
SELECT
OrderID, CustomerNameFROM
OrdersWHERE Country = 'USA'
This means: Show me only orders where the customer is from the USA.
4. GROUP BY – Summarise your data
When you want totals, averages, or counts, you need to group data.
SELECT Country, SUM(Sales) AS
TotalSalesFROM
OrdersGROUP BY
Country
Here, SQL groups the rows by Country
and sums the sales in each.
5. HAVING – Filter after grouping
HAVING
is like WHERE
, but it works with grouped data.
SELECT Country, SUM(Sales) AS
TotalSalesFROM
OrdersGROUP BY
CountryHAVING SUM(Sales) > 1000
This shows only countries with sales greater than 1000.
6. ORDER BY – Sort your results
Finally, use ORDER BY
to control the order of rows.
SELECT Country, SUM(Sales) AS
TotalSalesFROM
OrdersGROUP BY
CountryORDER BY TotalSales DESC
This sorts the results so the countries with the highest sales appear first.
Putting It All Together
SQL commands often follow this order:
S → F → W → G → H → O
SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY
👉 To make it stick, just remember this phrase:
“Silly Frogs Wear Green Hats Often.”
- S = SELECT (what you want)
- F = FROM (where it’s stored)
- W = WHERE (filter rows)
- G = GROUP BY (summarise data)
- H = HAVING (filter groups)
- O = ORDER BY (sort results)