WITH Clause vs Subqueries (And when to use each)

I’m a little confused between the WITH clause and a subquery. How do we know when to use which, and how do the use-cases between them differ? Thanks in advance!

Hello @text2418761122 ,

A big advantage with using the WITH, a temporary table, is that it can be reused. So if you have a situation where you need to reuse the query, use a WITH clause. The other argument is that a WITH clause is more readable.

More details here: SQL for Data Analysis: Subquery vs. CTE | by Aaron Zhu | Towards Data Science

3 Likes

Awesome! wasn’t aware the WITH clause was also known as CTE. thanks so much :slight_smile:

1 Like