cte_vs_subquery.txt (463B)
# Difference between CTE and sub-query -> A CTE can be named, a sub-query can only be aliased. This means that a CTE can be referenced many times within a complex SQL query, while a sub-query would have to be re-executed each time. So a CTE can allow for better code reuse. -> Code readability. As CTE's go to the front of the Query, it can be a lot less mentally taxing to understand compared to trying to read sub-queries that have 4-5 layers of nestedness.