
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Welcome to Subquery Magic. My goal is to help take the mystery out of subqueries and show you there is no magic to them at all!
By the time you have completed the course, you will have a thorough understanding of subqueries, be able to write your own, and know when it’s best to use them.
After completing this course know what subqueries are, and how to recognize them within a SQL query.
The PizzaDB is used for all lessons and code exercises within this course. It is compatible with MySQL, PostgreSQL, and MS SQL Server. So if you wish, use the included SQL DDL (script) to create your own database.
Regardless, you want to download the Pizza DB ER Diagram so you understand what tables are used in the lessons.
In this I'll walk through some highlights to get you started using the Pizza DB with SQL Server.
In this I'll walk through some highlights to get you started using the Pizza DB with MySQL.
In this I'll walk through some highlights to get you started using the Pizza DB with PostgreSQL.
Write a subquery whose result is displayed as a column in your main query.
Subqueries can be used any where within an expression. See how to do so from within the column list.
In a correlated subquery, values from the outer query “drive” the inner query.
Using SQL we'll walk through each step of the correlated sub query so you can see how they work.
Learn to combine data from more than one table using a correlated subquery.
Subqueries get a bad wrap, is is justified?
Familiarize yourself with EXISTS and how to use it to test whether a subquery returns rows.
Learn how to use the IN clause in combination with a subquery to test membership. Long story short, a subquery can be used to generate the membership list you used to "hard-code."
The power of using a subquery in the HAVING clause is now you don’t have to hard-code values within the comparisons. You can rely on the subquery’s results to do so for you
After completing this lesson you'll understand how to use a subquery in the HAVING clause and correlate it with an outer query.
After completing this lesson you'll understand how to use a subquery in the HAVING clause and correlate it with an outer query.
Understand how to create a derived table, and that derived tables are subqueries in disguise.
Learn to combine derived tables to one another, and why this is a benefit to all query writers.
In this course, you will learn the fundamentals of subqueries and how to use them effectively in your MySql, PostgreSQL, or MS SQL Server SQL statements. You will learn about different types of subqueries, including correlated and uncorrelated subqueries, and how to use them to solve complex problems. You will also learn about common pitfalls to avoid when working with subqueries, and how to optimize their performance in your queries.
By the end of this course, you will have a solid understanding of how to use subqueries in your SQL statements, and be able to apply this knowledge to a wide range of real-world scenarios.
In this Course you will Learn to:
Know and understand subqueries.
Identify subqueries in SQL.
Use subqueries in your select statement to make your queries more robust and less reliant on hard coded values.
Harness the power of derived tables to work around SQL limitations. Derived tables are also known as subqueries in the FROM clause.
Use subqueries in the WHERE clause with EXISTS and IN
Use subqueries with SUM, MAX and other Aggregate functions in GROUP BY and HAVING.
Write correlated subqueries so that your subquery is able work with the outer query to become more flexible and robust.
Nothing is worse than
Being excited to learn something new but not knowing where to start.
Wasting time learning the wrong features.
Being overwhelmed with options and not know which to use.
Imagine Having...
Knowledge - Knowing how to quickly use subqueries to take your SQL to the next level.
Confidence - Feeling good that you’re on the right track.
Accomplishment - Having a sense of accomplishment that you've learned something most cannot.
Fun - Actually having fun learning SQL subqueries!
By the time you’ve completed this SQL course you’ll have an appreciation of subqueries, overcome your fear, and able to write correlated queries to make your SQL more robust.