SQL for Data Analysts: The Complete Beginner Guide with Real Examples

SQL for Data Analysts

📚 In This Guide

If you are planning to become a data analyst, there is one skill you should probably learn before jumping into Python or Power BI: SQL.

Why? Because companies have plenty of data, but that data is not always sitting neatly in an Excel sheet waiting for you to analyse it. It is stored in databases, and SQL is how you get the information you need.

According to GrowAI’s SQL beginners guide for data careers in India, SQL appears in 55% of data analyst job postings in India. That makes it a useful skill to prioritise when preparing for these roles.

The good news is that you do not need a programming background to get started. Let’s walk through the SQL basics for data analysts, the queries you will actually use, the questions interviewers ask, and how to practise until you feel comfortable writing queries yourself.

SQL for data analysts: Quick answer

SQL helps data analysts retrieve, filter, combine, and analyse information stored in databases. The essential topics to learn are SELECT, WHERE, GROUP BY, HAVING, JOINs, subqueries, and window functions.

For beginners, six to eight weeks of consistent practice can provide a useful foundation for entry-level SQL interviews. You should also learn Excel and a visualisation tool such as Power BI or Tableau.

Free practice options include SQLZoo, HackerRank, and LeetCode.

SQL helps data analysts retrieve, organise, and understand information stored in databases.

Why learn SQL before Excel or Python?

This is the first thing most beginners ask: SQL, Excel or Python first? For data analytics, the honest answer is SQL.

Excel is brilliant when your data fits on a screen, say a few thousand rows. But almost every company beyond a certain size keeps its data in relational databases, not spreadsheets. When a manager asks which product sold the most last quarter across 2 million transactions, that answer lives in a database. SQL is how you ask for it.

Python is more powerful, sure, but it needs some programming context before it clicks. SQL reads closer to plain English. Take this: SELECT customer_name FROM customers WHERE city = ‘Pune’. You can almost read that without knowing a thing about SQL. Start here, and Python gets much easier afterwards because SQL already teaches you to think in data.

If you’re wondering “do I need Python or SQL first for data analytics?”, that’s your answer. SQL plus Excel is still the entry ticket to most data analyst roles in India, and Python comes next.

What is SQL? A simple explanation

Picture a database as a collection of neat tables. Each table is like a spreadsheet with rows and columns: a customers table, an orders table, a products table. SQL is the language you use to ask those tables questions. Which customers ordered last month? What’s the revenue by product category this quarter? Which five salespeople brought in the most?

Every one of those is a SQL query, and the basic shape never changes:

SELECT what_you_want
FROM which_table
WHERE some_condition;

That’s the skeleton of nearly every query you’ll write. Joins, aggregations and window functions all just build on top of it. Once this clicks, the rest layers on much more easily. So when people ask “what SQL do data analysts actually use?”, it’s mostly this skeleton with a few power-ups. Here are the seven that matter.

SQL queries retrieve specific information from a database by selecting and filtering records.

7 SQL concepts every data analyst should learn

1. SELECT and WHERE: the foundation

SELECT picks the columns. WHERE filters the rows.

SELECT customer_name, order_value
FROM orders
WHERE city = 'Pune' AND order_value > 5000;

Real use: “Show me all high-value customers from Pune.” An analyst runs this before building a regional dashboard.

2. GROUP BY and aggregate functions

GROUP BY bundles rows with the same value so you can total, average or count each bundle.

SELECT region, SUM(sales) AS total_sales
FROM sales_data
GROUP BY region
ORDER BY total_sales DESC;

Real use: the weekly regional sales summary. Almost every analyst writes some version of this every single week.

3. HAVING: the filter GROUP BY needs

Here’s the WHERE vs HAVING SQL difference in one line: WHERE filters rows before grouping, and HAVING filters groups after. Mixing them up is one of the most common beginner slip-ups in interviews.

SELECT region, SUM(sales) AS total_sales
FROM sales_data
GROUP BY region
HAVING SUM(sales) > 100000;

Real use: “Which regions crossed ₹1 lakh in sales this month?” WHERE can’t do this, because the sum doesn’t exist until GROUP BY has run.

4. JOINs: connecting tables

Real data is spread across tables, and joins bring it together. This is where SQL joins explained for beginners gets simple: INNER JOIN returns only the matching rows. LEFT JOIN returns everything from the left table plus matches from the right, and where there’s no match you get NULL.

SELECT c.customer_name, o.order_value
FROM customers c
INNER JOIN orders o ON c.customer_id = o.customer_id;

Real use: you have customers in one table and orders in another. The join tells you who bought what. Analysts also use RIGHT JOIN occasionally, but INNER and LEFT cover most day-to-day work.

SQL JOIN combines related records from different tables using a common column.

5. Subqueries: a query inside a query

A subquery is a SELECT tucked inside another SELECT. It’s handy when you need to filter by a number that has to be calculated first.

SELECT customer_name, order_value
FROM orders
WHERE order_value > (SELECT AVG(order_value) FROM orders);

Real use: “Show me every order above the average order value.” The inner query finds the average, and the outer one uses it as the filter.

6. Window functions: the most tested topic in Indian interviews

GrowAI’s guide points out that window functions are the single most tested SQL topic in data analyst interviews in India. They calculate across a set of related rows without collapsing your results the way GROUP BY does.

SELECT employee_name, department, salary,
       RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS salary_rank
FROM employees;

Real use: “Rank employees by salary within each department.” GROUP BY would squash the rows. A window function keeps every row and adds the rank beside it. If you’re asking “what are window functions in SQL?”, that’s the one-sentence answer.

7. The second highest salary query

According to Weekday’s verified SQL interview questions for India 2026, the second highest salary query is the single most asked SQL question in the country. Know two ways to write it:

-- Method 1: Subquery
SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);
-- Method 2: Window function
SELECT salary AS second_highest
FROM (
    SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk
    FROM employees
) ranked
WHERE rnk = 2;

Interviewers sometimes follow up with “can you do it without a subquery?” Having both methods ready makes you look prepared.

Seven foundational SQL concepts include SELECT, WHERE, ORDER BY, GROUP BY, JOIN, aggregate functions, and CASE WHEN.

SQL interview questions data analyst needs to practice

After learning the concept, you need to answer those questions without referring to your notes. Some examples are listed below which will help you.

Concept questions

  • Difference between WHERE and HAVING in SQL?
  • Difference between INNER JOIN and LEFT JOIN?
  • What is the window function, and in what scenario would you apply it?
  • What are subqueries?
  • Difference between UNION and UNION ALL?

Write a query questions

  • Second highest salary in employee table
  • Duplicate records in the table
  • Employees whose salary is greater than the average salary of that department
  • Customers who have purchased in January but not in February
  • Total sale of each product category

Advanced questions for experienced candidates

  • How can you debug a slow SQL query?
  • Explain the concept of database indexes and their usage.
  • How can you avoid the count of duplicate records in the report?

You do not need to learn only the answer to such questions. Instead, you must be able to write queries, explain your process, and answer even a little change in the question.

For instance, an interviewer might ask you for the highest salary, then for the second highest, then for the third highest excluding any duplicate values. The wording changes, but the thinking behind the query stays the same.

How long does it take to learn SQL for data analytics?

For those beginning from scratch, an appropriate period would be 6 to 8 weeks, during which time one can build the basics of SQL knowledge and solve SQL-based interview problems.

Regular practice is needed for at least 45 to 60 minutes every day. This period will vary depending on one’s starting point, consistency of practice, and the difficulty level of the questions.

Here is a simple learning plan:

WeekWhat to learn
1 to 2SELECT, WHERE, ORDER BY, COUNT, SUM and AVG
3 to 4GROUP BY, HAVING and JOINs
5 to 6Subqueries and window functions
7 to 8Interview questions and small projects

You can practise for free on SQLZoo, HackerRank, and LeetCode’s database problems.

Start with guided exercises. Once you feel comfortable, work with a real dataset and answer questions such as which products sell best or which months generate the most revenue. That is how you move from recognising SQL commands to using SQL to solve problems.

Want to learn SQL alongside the other tools used in data analytics? FirstBit’s data analytics course at FirstBit Pune covers SQL, Excel, Python, Power BI, Tableau, and other data-related skills as part of a structured programme. You can explore the curriculum and book a demo to see whether the course fits your learning goals.

What should you learn after SQL?

SQL is an excellent place to start, but it certainly will not be all the knowledge you will require as a data analyst.

Once you have gained SQL knowledge, concentrate on:

  • Excel: For spreadsheet usage, quick calculations, and verification of data.
  • Power BI or Tableau: For creating dashboards, graphs, and presentation of results.
  • Python: Especially Pandas, for data cleaning and analysis.
  • Basic statistics: For learning averages, distributions, trends, and comparisons.

If you are interested in studying Python along with SQL, consider taking a Python with data science course at FirstBit.

Are you still not sure whether to become a developer or a data analyst? Consider comparing the Python full stack and data analyst job opportunities to see the difference between the two career choices.

To know more about salary expectations for data analysts in Pune, please read about salaries for data analysts in Pune after doing a course.

A beginner SQL roadmap progresses from fundamentals to queries, analysis, and practical projects.

Ready to put your SQL skills into practice?

Learning SQL gets a lot easier when you stop thinking of it as a bunch of commands and start using it to answer real questions.

Start with the simple things. Find customers from a city. Add up sales for each month. Compare how different departments are doing. Then slowly move on to JOINs, subqueries and window functions.

You don’t have to know everything in a week. What really matters is being able to look at a business question, figure out what data you need and write a query that gives you the answer.

If you would prefer a structured learning path, FirstBit’s data analytics course at FirstBit Pune brings SQL together with Excel, Python, Power BI, and other practical skills. Explore the course and book a free demo to understand the curriculum before making a decision.

Frequently asked questions

Data analysts commonly use SELECT, WHERE, GROUP BY, HAVING, JOINs, aggregate functions, subqueries, and window functions. The exact queries depend on whether they are analysing sales, customers, operations, finance, or another area of a business.

Six to eight weeks of consistent practice can help beginners build a foundation for entry-level interviews. Becoming comfortable with real datasets and unfamiliar questions may take longer, so keep practising beyond the initial learning period.

WHERE filters individual rows before grouping. HAVING filters groups after GROUP BY and is commonly used with aggregate calculations such as SUM and COUNT.

Window functions calculate values across related rows without combining them into a single row per group. Data analysts use functions such as RANK, ROW_NUMBER, LAG, and LEAD to rank records and compare values.

Finding the second-highest salary is a useful and widely practised SQL interview problem. It tests whether you understand subqueries, aggregate functions, and window functions. However, there is no single question that every Indian employer asks most frequently.

For most beginners targeting data analyst roles, learning SQL first is a practical choice. You can then add Excel, Power BI or Tableau, and Python as your analytical skills develop.

SQL alone is generally not enough for most data analyst roles. Combine it with Excel, a visualisation tool, basic statistics, and practical projects that demonstrate your ability to answer business questions.

Become Job-Ready with Firstbit Solutions

Join First Bit Solutions and learn from industry experts with live projects, placement assistance, mock interviews, and hands-on training.

Related Blogs