Back to articles list Articles Cookbook
8 minutes read

How to Practice Advanced SQL Online with LearnSQL.com

Want to go from intermediate to advanced SQL user? You’ll need to practice! Here are some ways you can practice advanced SQL online.

You’ve seen how SQL helps you make data-driven decisions. Perhaps you’ve even learned some advanced features. But you’d like to become an expert—and for that, you need practice, practice, and more practice. Is it possible to get advanced SQL practice online?

Taking SQL to the Next Level

What is advanced SQL? There’s no single answer to that question. Most courses (including university degree programs) don’t go much beyond extracting and aggregating data, but SQL can do so much more. If you really want to make SQL work for you, you need to learn and practice advanced SQL.

Here are a few areas of SQL that are not usually taught at a basic or intermediate level:

  • Features introduced in the 1999 and 2003 language upgrades.
  • Database optimization, including best practices for designing indexes.
  • Stored procedures, user-defined functions, and triggers.
  • Query optimization.

Which of these should you learn? It depends on your role. Database administrators will definitely need a good knowledge of optimization topics — it’s their responsibility to make sure the database runs efficiently. Software developers need to know how to write stored procedures and functions to make code reusable.

Almost everyone can benefit from understanding how to use the newer features of SQL:

  • Data analysts and decision-makers use them to analyze the data in more flexible and meaningful ways.
  • Database administrators and database engineers will find them useful when carrying out ETL (Extract, Transform and Load) operations.
  • Software developers use them to quickly program complex data operations.

LearnSQL.com offers many courses and learning tracks for advanced users. And best of all, there are lots of options that allow you to get enough advanced SQL practice online to consolidate your skills. Every month, LearnSQL.com publishes a monthly practice set of interactive exercises. In odd-numbered months, these are advanced challenges. All the exercises allow you to work online against an actual database and solve the kind of problems you’ll encounter in the real world.

Advanced SQL Features

In the previous section, I mentioned features added to the SQL language. Interestingly, they are still referred to as ‘new features’, although they have been around for 20 years. This is because they are not well-known – so many people are content with using SQL at the basic level – and not all of them are available in all SQL dialects. In this section, I’ll have a brief look at these features. If you’re interested in the history of SQL, you may like to read this article.

GROUP BY Extensions

These extensions give you much more flexibility in grouping and aggregating data. They are invaluable both for data analysis and for ETL processes.

  • ROLLUP: The standard SQL GROUP BY clause only allows you to see aggregates at the lowest level of grouping. For example, if you request total sales data by area and product, you will see totals for each product but not for the area as a whole. ROLLUP allows you to see totals for the area as well as the product.
  • CUBE: This is similar to ROLLUP, but it creates aggregates for every possible grouping combination. It’s widely used for ETL when creating a data warehouse.
  • GROUPING SETS: This feature allows you to do multiple groupings within a single query. You can achieve the same effect by combining queries with the UNION feature, but this is much simpler, faster to run, and easier to understand.

The GROUP BY extensions give you more flexibility and allow you to create complex analyses and reports. LearnSQL.com’s  GROUP BY Extensions in SQL course covers all of these topics, and has over 60 practical exercises. It’s also available for PostgreSQL, MS SQL Server, and MySQL, since there are some slight differences in these dialects.

Window Functions

Window functions get their name because they allow you to ‘look through the window’, and access aggregate data in conjunction with each row in your query.

Alongside each row in your result set, you can show aggregate functions such as totals, averages, maximum and minimum values, and counts. The aggregates could be for the group to which the row belongs or for the data as a whole. This is extremely useful for comparing an individual item to a group. For example, you could use it to compare a student’s grade to the class average or to see what percentage of total sales were made by each product group. In addition, you can use the RANK() function to rank each item – e.g. to create a list of customers ranked by their total purchases.

Data analysts can use these features to include rankings, running totals, or moving averages in a report. It’s also great for doing year-on-year comparisons.

LearnSQL.com offers a full Window Functions course with over 200 interactive exercises. It’s available for PostgreSQL, MS SQL Server, and MySQL 8.

Recursive Queries

Recursive queries are implemented as Common Table Expressions (CTEs, also known as WITH clauses). They are essentially just named subqueries, but CTEs have the added advantage of being processed recursively over a hierarchy of data.

For example, imagine you have several stores. Each store has several departments, and each department has several products. Recursive queries can work through that hierarchy, processing each item against its parent item and producing data suitable for a tree or a graph.

CTEs allow you to break long and complex queries into smaller chunks, thus making the code more readable and less prone to errors.

LearnSQL.com offers a Recursive Queries course for standard SQL, and also for MySQL, PostgreSQL, and SQL Server. The course includes over a hundred interactive exercises.

Practice Makes Perfect

Since SQL is a hands-on skill, knowing the theory is not useful unless you have plenty of practice. The advanced topics are quite complex; you need to try things out for yourself if you want to remember them. If you want to be able to analyze data in lots of different ways, you need to know exactly what SQL can do. Only practice can give you that in-depth knowledge

It’s not always easy to get the practice you need. You may have access to your own database, but unless you have a good set of test data with many different variations, you won’t really be able to try out all the different querying options in a meaningful way. Also, not all versions of database management software have the advanced options available. This is especially true if you’re using an older version of the software. (Or if you are using MySQL, which doesn’t yet have full support for all features.) Some online SQL practice options, such as W3Schools Tryit Editor, don’t support the newer features of SQL.

Advanced SQL Practice with LearnSQL.com

So, where’s the best place to practice? LearnSQL has several options where you can get advanced SQL practice online. Let’s look at a few of them:

  • Monthly SQL Practice.
    • Published every month.
    • Odd-numbered months are advanced challenges; even-numbered months are basic SQL challenges.
    • Each month has a different theme and different sets of data, so you’ll be able to practice advanced SQL in many different ways.
    • Each month has between 8 to 15 exercises on 3 to 5
  • Windows Functions Practice Set.
    • This includes 100 interactive online exercises.
    • Uses 3 real-life databases.
    • You will practice on a commercial store and sales set, work with data from a series of running competitions, and learn to analyze website traffic and conversions.
  • 2023 Monthly Practice Sets - Advanced
    • This is a consolidation of all the advanced exercises from the monthly challenges for 2023.
    • It contains more than 80 advanced SQL exercises.
    • It will probably take you around 6 hours to complete
  • 2022 Monthly Practice Sets - Advanced
    • This is a consolidation of all the advanced exercises from the monthly challenges for 2022.
    • It contains more than 80 advanced SQL challenges.
    • It will probably take you around 6 hours to complete
  • 2021 Monthly Practice Sets - Advanced
    • Again, this is a consolidation of the advanced monthly challenges from 2021.
    • It has over 90 interactive advanced exercises
    • You will probably need around 6 hours to complete it.

The LearnSQL.com Learning Experience

Maybe you’re interested in using LearnSQL.com to practice advanced SQL. What kind of learning experience can you expect? Let’s look at the Advanced SQL track to find out.

Every exercise contains three parts: an explanation, a task, and a result with feedback. You first read an explanation of the topic. The explanations and examples look like this:

How to Practice Advanced SQL Online

Then you’re given an exercise to complete. You run your code and see the results. The course gives feedback on how you did; if you’re stuck, you can ask for hints. Here’s a screenshot of a completed exercise:

How to Practice Advanced SQL Online

If you run into trouble, you can ask a question via the Disqus tab and our friendly support team will reply to your questions.

Start Practicing Advanced SQL Today!

If you want to become an SQL expert, there’s no better way to achieve your aim than practicing advanced SQL as much as possible. You’ll be able to do your job better, ace those interview questions, and open up more career opportunities.

There’s no time like the present, so make your first move towards becoming an expert now!