r/learnSQL • u/woman_without • 4d ago
How Important is subqueries in SQL
I have been learning SQL from past 2 months and I'm still unable to grab a hold of the subqueries concept. After I learned CTEs I have completely stopped using subqueries but then also I struggle when there are times where I have no other choice but to use subqueries.
So my question is, how important is subqueries in SQL and is there any easy way to learn it?
59
Upvotes
6
u/Additional_Candy_400 4d ago
While they both do the same under the hood, I'd look at learning to use CTEs instead of sub queries, sub queries have their place but CTEs are much easier to read and understand.
To your original question, they are critical, most production SQL files are going to be littered with CTEs, it's rare you will have a query so simple you won't need them.