Our website uses cookies. By using this website, you agree to their use in accordance with the browser settings. You can modify your browser settings on your own. For more information see our Privacy Policy.



Recursive Queries in MySQL 8

Do you want to be able to process trees and graphs in MySQL? Are you using MySQL 8 or higher? Learn how to write recursive queries and you’ll soon be producing concise and powerful SQL queries!

Table of contents

10 free interactive coding challenges

Lifetime access


limited to this course only


Buy now

Want a better deal?


Get unlimited lifetime access to all 65 present and future courses

Save $450

Unlimited lifetime access


to all 65 present and future courses



75% OFF

Buy now

Interactive exercises

18 h

Estimated time


Users enrolled


316 ratings

This interactive online MySQL course will teach you how to use Common Table Expressions (CTEs) and recursive queries in MySQL 8 and up. If you are serious about working with databases and becoming a SQL expert, you need to know these features.

Recursive SQL queries let you process hierarchical structures (such as management hierarchies, family trees, or road connection graphs) in SQL. When you understand recursion, you can easily work with trees and graphs stored in a MySQL database.

CTEs (Common Table Expressions, also known as WITH queries), are essentially named subqueries. They let you organize your SQL query and name parts of it; this makes your work clearer and more readable. CTEs also let you organize computations into multiple phases, which makes long queries more understandable.

Common Table Expressions and recursive queries were introduced to MySQL in 2018; they are now available in version 8.0 and higher. After completing this online MySQL course, you will be able to use the acquired knowledge in work with other SQL databases; just check minor syntax differences in your database’s documentation.

This course covers simple CTEs, nested CTEs, and recursive CTEs. You will learn how to manage your SQL queries with CTEs, how and when to nest CTEs, and how to use recursive CTEs to move through hierarchical data models.

The course is interactive. You practice by writing real SQL code and solving exercises directly in your web browser. Our online platform runs your code and verifies your solution. You don't need to install any software on your computer.

This course is intended for intermediate users. We assume that you know the basics of SQL, including:

  • How to select from a single table, including writing complex WHERE conditions
  • How to JOIN tables
  • How GROUP BY and HAVING work
  • How SQL subqueries work

If you are new to MySQL, start with our SQL Basics in MySQL course and come back to this course when you’re comfortable with those concepts.

What Do You Need to Take This Course?

  • A web browser and an Internet connection
  • Knowledge of basic SQL, including JOINs and GROUP BY clauses

What Am I Going To Get from This SQL Course?

You will discover how to:

  • Understand and use basic Common Table Expressions in MySQL 8 and up
  • Organize long SQL queries using simple and nested CTEs (MySQL 8 and up)
  • Use recursive CTEs
  • Write recursive CTEs that traverse a hierarchical data model

Who Should Take This Course?

  • Beginning database analysts who use MySQL
  • Developers who want to keep their knowledge of MySQL current
  • Students taking classes in relational databases using MySQL 8
  • Anyone who wants to learn Common Table Expressions in MySQL

What's In It for Me?

  • 114 interactive exercises. Learn at your own pace, from anywhere and at any time. Interactive, hands-on learning improves retention.
  • Lifetime access to the course. When you purchase the course, you’ll get instant personal access to all of its content.
  • Certificate of completion. After you successfully finish all of the exercises, you’ll get a downloadable PDF certificate to showcase your accomplishment.
  • 30-day money-back guarantee. If you’re not satisfied with the quality of the course, you can get a refund within 30 days of your purchase.
  • Hints and help. There are hints available in the exercises to help you if you get stuck. You can also ask our learning community for help through the Disqus tab. Or drop the course creators a line – we’ll be more than happy to answer! 😉

Table of contents


Paid content


Course progress


Exercises completed

Reviews (0)

Average rating



316 ratings


5 stars


4 stars


3 stars


2 stars


1 stars