CadetX
Data Skills

SQL for Data Analysts: 15 Essential Queries Every Beginner Should Know (With Examples)

SQL is the one skill in almost every data analyst job description. Learn these 15 queries and you'll be able to answer the vast majority of real analytical questions you'll face on the job.

KM
Kavin Muthukumar
Founder, CadetX UK · Updated September 2026

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.

1

SELECT specific columns

Pull only the columns you need, not everything. Cleaner and faster than SELECT *.

SELECT first_name, last_name, city
FROM customers;
2

WHERE — filter rows

Keep only the rows that meet a condition. The workhorse of everyday analysis.

SELECT *
FROM orders
WHERE country = 'UK';
3

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;
4

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.

5

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;
6

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;
7

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;
The classic interview trap: WHERE filters rows before grouping; HAVING filters groups after. Mixing these up is one of the most common beginner mistakes — and a favourite interview question. We cover more of these in our data analyst interview questions guide.

Combining Tables and Adding Logic

Real data lives across multiple tables. These queries let you join it together and add conditional logic.

8

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;
9

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;
10

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;
11

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
);

Want to practise these and get certified?

Reading SQL and writing SQL are different skills. The CX Learn SQL track lets you practise real queries interactively and earn a free, verified certificate you can add to your CV.

Learn SQL on CX Learn →

Analyst Favourites: The Practical Queries

These come up constantly in real analytical work — and impress in interviews.

12

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';
13

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;
14

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';
15

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:

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:

Free · SQL Certificate

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 →
100% 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 →
Paid · Placement

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.

KM
Kavin Muthukumar Founder, CadetX UK

Kavin is the founder of CadetX, a career-launch platform helping students build real, employer-valued experience in data and AI roles.