LogoInterview Master

The only SQL learning roadmap you need

Learning SQL can be overwhelming. But it doesn't have to be.

In fact, SQL is one of the easiest coding languages out there. If this is your first time dipping a toe into programming... SQL is a great place to start.

But where do you even begin?

It’s easy to get lost in the sea of tutorials, courses, and practice problems.

I got you. Here is the only SQL learning roadmap you need.

Btw, the best way to retain the knowledge you learn is through practice. Get your practice in at InterviewMaster.AI 💪

Step 0: Learn about relational databases

When I first started learning SQL , I jumped straight into learning the basics. SELECT, FROM, WHERE etc.

Don't do this.

Start with the foundations -- understanding WHAT is a relational database.

Why is learning about relational databases important?

SQL is built for relational databases. So to understand SQL, you need to first understand relational databases.

So how do you learn about relational databases:

I promise you. This extra 15 minutes of learning upfront, will save you a lot of future headaches.

Step 1: Start with the basics

Now that you know relational databases, you are ready to start writing your first SQL query.

The basics involve extracting data from a single table. As you know, relational databases contain many tables. But before we start getting data from 2+ tables, let's focus on getting data out of just one table.

  • Writing simple SELECT statement

  • AS for aliasing columns or tables

  • Using WHERE to filter data

  • Sorting with ORDER BY

  • Limiting results with LIMIT or TOP

Step 2: Data cleaning and filtering

Whether you're working in Python, Excel or SQL, Data Cleaning is one of the first steps of any project.

It is the most painful (but most important) part of being a Data professional.

The next step of your learning journey will be about how to clean and manipulate data. This builds on the previous section where you learn to get data out of a table. At the end of this section, you'll be able to extract data in the format that you want it.

  • Using DISTINCT to filter data

  • Pattern matching with LIKE and wildcards %

  • Using BETWEEN and IN for range filtering

  • Filtering with multiple conditions using:

    • OR

    • AND

    • NOT

  • Handling null values using COALESCE

  • Case expressions with CASE WHEN

  • Casting and converting data types using CAST and CONVERT

Step 3: Data aggregation

Previously, everything we had learned was one row in → one row out.

Now we're going to combine the data in multiple rows into a single row. Kind of like a pivot table in Excel.

This is where we can do summations, averages, and other aggregations.

  • Common aggregate functions:

    • SUM

    • AVG

    • MIN

    • MAX

    • COUNT

  • Grouping data with GROUP BY

  • Filtering grouped data using HAVING

  • Using nested aggregations (e.g., AVG(SUM(sales)))

That last bullet -- nested aggregations -- will feel like mental gymnastics at the start. But a lot of real world problems require it.

Step 4: Combining tables

Ok, this is where the fun really begins. Remember how we learned about relational databases at the start?

Now you're going to learn how to extract table from multiple tables and combine them.

At this step, you'll learn about JOINs (combining tables side-by-side) and UNIONs (combining tables top-to-bottom).

  • Understanding different types of joins:

    • INNER JOIN

    • LEFT JOIN

    • RIGHT JOIN

    • FULL OUTER JOIN

    • SELF JOIN

  • Combining datasets with:

    • UNION

    • UNION ALL

    • EXCEPT

    • INTERSECT

  • Using CROSS JOIN for Cartesian products

  • Joining on multiple columns with composite keys

Step 5: Window functions

Window functions often get confused with aggregation functions.

What's the difference?

→ In an aggregation function, you get one output row aggregating all your input rows.

→ In a window function, you get one output row for every input row.

If I were to be honest, it took me years to really master window functions. Be kind with yourself, this is one of the more complex SQL topics you'll learn.

  • Basics of window functions using OVER

  • Partitioning data using PARTITION BY

  • Window frames for precise calculations:

    • ROWS BETWEEN for specific row ranges

    • RANGE BETWEEN for value-based ranges

  • Window Functions for Ranking:

    • RANK

    • ROW_NUMBER

    • DENSE_RANK

  • Window Functions for Navigation:

    • LAG

    • LEAD

    • NTILE

    • LAST_VALUE

    • FIRST_VALUE

    • PERCENT_RANK

  • Aggregates with window functions, like SUM and AVG

Step 6: Subqueries and CTEs

We're done with the hardest part, I swear. Window functions are (in my opinion) the hardest thing to learn in SQL.

All subsequent steps will feel like a cake walk compared to window functions.

The next step, we're going to learn about subqueries and CTEs. These unlock multi-step analyses. For example, say we want to calculate the average purchase amount across all customers. We would first calculate the purchase amount per customer, and then average that across the customer base.

  • Simple and correlated subqueries

  • Writing Common Table Expressions (CTEs) with WITH

  • Recursive CTEs for hierarchical or iterative data

  • Choosing between subqueries and CTEs for clarity and performance

Step 7: Table Manipulation

Up to this point, we have been a consumer of data. We take the structure and data of the tables for granted. We are at the mercy of the data tables that are available to use.

Next up, we are going to learn to edit the data that is in our database.

As you can imagine, this will unlock even more powerful and complex analyses in SQL.

  • INSERT data into tables

  • UPDATE existing records

  • DELETE records from tables

  • Understand the difference between TRUNCATE vs. DELETE

  • Defining default values with constraints using DEFAULT

As the Spiderman quote goes, "with great power comes great responsibility". Use all of these functions with caution and with intention.

[Bonus] Step 8: Query Optimization

Phew, we're on the last step. This is where you take your SQL skills to the next level. This where you master SQL.

There are so many ways to optimize your SQL queries. Here are just a few to get you started:

  • Using indexes effectively

  • Understanding execution plans

  • Optimizing joins and subqueries

  • Avoiding common pitfalls like:

    • Unnecessary SELECT *

    • Redundant DISTINCT or ORDER BY

    • Overusing correlated subqueries

SQL might seem like a lot at first, but once you break it down step by step, it’s totally manageable.

The most important part of your learning journey? Practice.

Get hands-on experience through building portfolio projects or through practice question.

If you want real-time feedback on your SQL queries, check out InterviewMaster.AI.