If you learn one technical skill to become a data analyst, make it SQL. It's the language you use to pull data out of databases, and it appears in nearly every data analyst job advert. The good news: you don't need to learn all of SQL. A focused set of queries covers the overwhelming majority of day-to-day analytical work.
This guide walks through 15 essential SQL queries every beginner should know, each with a clear example and a note on when you'd actually use it. Work through them in order — they build on each other. If you'd rather learn interactively and earn a certificate as you go, you can follow the CX Learn SQL track alongside this post.
The Basics: Getting and Filtering Data
These four are the foundation — you'll use them in almost every query you ever write.
SELECT specific columns
Pull only the columns you need, not everything. Cleaner and faster than SELECT *.
SELECT first_name, last_name, city FROM customers;
WHERE — filter rows
Keep only the rows that meet a condition. The workhorse of everyday analysis.
SELECT * FROM orders WHERE country = 'UK';
ORDER BY — sort results
Sort by a column, ascending or descending. Useful for "top" or "latest" questions.
SELECT product_name, revenue FROM sales ORDER BY revenue DESC;
DISTINCT — unique values
Remove duplicates to see the distinct values in a column — e.g. every country you sell to.
SELECT DISTINCT country FROM customers;
Aggregating: Turning Rows Into Answers
This is where SQL becomes analysis — summarising many rows into a single number or a grouped summary.
Aggregate functions (COUNT, SUM, AVG)
Summarise a whole column into one value — a count, total, or average.
SELECT COUNT(*) AS total_orders, SUM(revenue) AS total_revenue, AVG(revenue) AS avg_order_value FROM sales;
GROUP BY — summarise per category
The most important analytical query. Get a summary for each group — revenue per region, orders per month.
SELECT region, SUM(revenue) AS total_revenue FROM sales GROUP BY region;
HAVING — filter groups
Filter after grouping. Use it to keep only groups that meet a condition — e.g. regions above a revenue threshold.
SELECT region, SUM(revenue) AS total_revenue FROM sales GROUP BY region HAVING SUM(revenue) > 100000;
Combining Tables and Adding Logic
Real data lives across multiple tables. These queries let you join it together and add conditional logic.
INNER JOIN — matching rows from two tables
Combine two tables, keeping only rows that match in both.
SELECT o.order_id, c.first_name FROM orders o INNER JOIN customers c ON o.customer_id = c.customer_id;
LEFT JOIN — keep everything from the first table
Keep all rows from the left table, matched or not. Perfect for finding what's missing — e.g. customers with no orders.
SELECT c.first_name, o.order_id FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.order_id IS NULL;
CASE — conditional logic
Create categories on the fly — like bucketing orders into value bands.
SELECT order_id, CASE WHEN revenue > 1000 THEN 'High' WHEN revenue > 100 THEN 'Medium' ELSE 'Low' END AS value_band FROM sales;
Subquery — a query inside a query
Use the result of one query inside another — e.g. customers who spent above the average.
SELECT first_name, total_spent FROM customers WHERE total_spent > ( SELECT AVG(total_spent) FROM customers );
Analyst Favourites: The Practical Queries
These come up constantly in real analytical work — and impress in interviews.
Filter by date range
Almost every business question has a time dimension. Filter to a specific period with BETWEEN.
SELECT * FROM orders WHERE order_date BETWEEN '2026-01-01' AND '2026-03-31';
Find duplicate records
Group by the columns that define a duplicate, then keep groups with more than one row.
SELECT email, COUNT(*) AS cnt FROM customers GROUP BY email HAVING COUNT(*) > 1;
Combine multiple conditions
Use AND / OR to filter on several conditions at once.
SELECT * FROM sales WHERE region = 'North' AND revenue > 500 AND order_date >= '2026-01-01';
Window function: ROW_NUMBER / RANK
The step that separates beginners from confident analysts. Rank rows within groups — e.g. the top order per customer.
SELECT customer_id, order_id, revenue, ROW_NUMBER() OVER ( PARTITION BY customer_id ORDER BY revenue DESC ) AS rn FROM orders;
Don't worry if window functions feel advanced at first — get comfortable with queries 1–14, then come back to this one.
How to Actually Get Good at SQL
Reading queries isn't the same as writing them. The only way SQL sticks is by writing it yourself against real data, repeatedly. A few tips:
- Practise daily, in small doses. Fifteen minutes a day beats a three-hour session once a week.
- Write queries against real datasets — the ones in our portfolio project ideas are ideal.
- Say what each query does out loud — it's exactly how you'll explain them in an interview.
- Use a solid reference — the free W3Schools SQL reference is handy for looking up syntax as you go.
Learn, Practise, and Prove Your SQL
These 15 queries make you dangerous with SQL. To turn that into something employers can see, here's how CadetX helps — from practising and getting certified, to using SQL on real projects:
CX Learn SQL
Practise these queries interactively and earn a free, verified SQL certificate to put on your CV — the fastest way to prove your skills.
Learn SQL Free →Virtual Work Experience
Use your SQL on real, company-sourced projects and build a portfolio. Free, remote, 3 months, with a certificate at the end.
Apply Free →Data & AI Launchpad
Want the full path — skills, real projects, and placement support all the way to hired? Zero to Hired takes you there.
Start Training →Frequently Asked Questions
Is SQL enough to become a data analyst?
SQL is the single most important skill for a data analyst and is required in almost every role, but it is not the only one. Most analysts pair SQL with a spreadsheet tool and a visualisation tool such as Power BI or Tableau. That said, strong SQL is the biggest single step toward becoming job-ready.
How long does it take to learn SQL for data analysis?
Most people can learn the core querying skills covered in this guide in a few weeks of consistent practice. Reaching interview-ready confidence usually takes one to three months, depending on how often you practise on real datasets rather than only reading.
What SQL queries should a beginner data analyst know?
A beginner should be comfortable with SELECT, WHERE, ORDER BY, DISTINCT, aggregate functions with GROUP BY and HAVING, INNER and LEFT JOINs, CASE statements, subqueries, date filtering, finding duplicates, and a basic window function such as ROW_NUMBER.
What is the difference between WHERE and HAVING?
WHERE filters individual rows before any grouping happens. HAVING filters groups after aggregation, so it is used together with GROUP BY. For example, you use WHERE to keep only 2025 orders, then HAVING to keep only customers with more than ten orders.
Where can I practise SQL and get certified?
You can practise SQL free and earn a verified certificate through CadetX CX Learn's SQL track. Practising on real query problems and getting certified is a strong, low-cost way to prove your SQL skills to employers when you have no experience.