Basic CTE
12. CTE vs. subquery


Alright. The last thing we'll discuss in this part is the difference between subqueries and CTEs. In fact, all of the examples and exercises from this part could be rewritten with subqueries. For now, CTEs simply increase readability of your query. A query with a subquery will look similar to that with a CTE, but the CTE version makes your query look more structured and easier to read.

However, it is not possible to create correlated subqueries with CTEs. Don't worry, though -- you will soon find out that there are also certain things that CTEs can and subqueries can't do.


The query shows the average sum raised by those projects which succeeded. Change the version with a subquery into a version with a CTE.