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.

1974Year SQL was invented
#1Most used data skill globally
5 minTo write your first working query

Your first query

Every SQL query starts with SELECT (what columns you want) and FROM (which table). That is the entire foundation.

SELECT Salesperson, Region, Revenue
FROM SalesFact;

Filtering with WHERE

WHERE restricts which rows are returned. Only rows where the condition is true are included.

SELECT Salesperson, Revenue
FROM SalesFact
WHERE Region = 'North'
AND Revenue > 1000;
💡
Analyst tip: Always write WHERE before you write ORDER BY. Filter first, sort second — the database works more efficiently in that order.

Sorting with ORDER BY

SELECT Salesperson, Revenue
FROM SalesFact
ORDER BY Revenue DESC
LIMIT 5; -- top 5 only

Counting and summing

SELECT
  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.

SELECT Region, SUM(Revenue) AS TotalRevenue
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.

SELECT s.Salesperson, c.CategoryName, s.Revenue
FROM SalesFact s
INNER JOIN Category c ON s.CategoryID = c.CategoryID;
⚠️
Common mistake: Using INNER JOIN when you need a LEFT JOIN. INNER JOIN drops rows that have no match. LEFT JOIN keeps all rows from the left table. When in doubt, start with LEFT JOIN.

SQL vs Excel vs Power BI

🎯 Your Challenge

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.

FAQ

No. Use a free browser-based SQL tool — DB Fiddle (dbfiddle.uk) or SQLiteOnline.com let you create tables and run queries with no installation. Start there before worrying about databases.
SQL keywords (SELECT, FROM, WHERE) are case-insensitive — you can write them in lowercase. Column names and string values may or may not be case-sensitive depending on the database. Convention is to write keywords in uppercase for readability.
The core SQL covered here works in all major databases (MySQL, PostgreSQL, SQL Server, SQLite). Start with SQLite — it is embedded, requires no server, and works in DB Fiddle. The 95% of SQL you use daily is identical across all of them.
`