
How to Write a SQL Query within a SQL Query with a Subquery or Common Table Expression (CTE)
In the training video above, we walk through how to perform a subquery and a common table expression (also known as a CTE) in SQL. A subquery is a SQL query within another SQL query, and a common table expression (or CTE) is a similar, but slightly different concept. We’ll show you how to do both of these using SQL within Python, but these SQL concepts can be used in any SQL platform.
You can download the Jupyter Notebook used in the video here.
If you want to run the code alongside the video (not critical) and don’t already have Anaconda or Jupyter installed, check out the very beginning of the intro to Python training here to see how to Download Anaconda (free packaging of Python executor, the Jupyter Notebook IDE, and common Python packages) and launch a Jupyter Notebook. If you want to learn more about Pandas data manipulation, which we use briefly in the video, you can keep watching this intro to Python training.
If you want to learn more about SQL data manipulation, you can check out our intro to SQL training here, which covers selecting data from a data table, creating new columns, joining tables together, and aggregating and grouping data.
I hope you enjoy this overview of SQL queries within SQL queries through subqueries and CTEs! And now you’re free…to write a CTE!


