Riya's manager asks: "How many orders did each salesperson close last month, broken down by region?" She has the data — in a database with 800,000 rows. Excel would choke. Power BI needs a model first. SQL answers the question in four lines.
What SQL is (and is not)
SQL (Structured Query Language) is the standard language for reading and manipulating data in relational databases. It is not a programming language in the traditional sense — you do not write loops or build apps. You write questions, and the database answers them.
Your first query
Every SQL query starts with SELECT (what columns you want) and FROM (which table). That is the entire foundation.
FROM SalesFact;
Filtering with WHERE
WHERE restricts which rows are returned. Only rows where the condition is true are included.
FROM SalesFact
WHERE Region = 'North'
AND Revenue > 1000;
Sorting with ORDER BY
FROM SalesFact
ORDER BY Revenue DESC
LIMIT 5; -- top 5 only
Counting and summing
COUNT(*) AS TotalOrders,
SUM(Revenue) AS TotalRevenue,
AVG(Revenue) AS AvgOrderValue
FROM SalesFact;
Grouping with GROUP BY
GROUP BY is the SQL equivalent of a pivot table — it aggregates rows that share the same value in a column.
FROM SalesFact
GROUP BY Region
ORDER BY TotalRevenue DESC;
Combining tables with JOINs
Real databases split data across multiple tables. JOIN brings them together on a shared column.
FROM SalesFact s
INNER JOIN Category c ON s.CategoryID = c.CategoryID;
SQL vs Excel vs Power BI
Write a query that returns the total revenue per salesperson, for the North region only, ordered highest to lowest. Use SELECT, FROM, WHERE, GROUP BY, and ORDER BY together. Check your answer in the next guide.