r/SQLServer • • Jul 03 '26

Discussion sub queries

I'm studying SQL and am currently on the lesson about subqueries, but I just can't seem to wrap my head around it.

I'm struggling to get the different types of subqueries—and when to use each one—to stick in my mind.

Does anyone have any study materials on this? Maybe a YouTube video tutorial?

THANKS!

5 Upvotes

33 comments sorted by

View all comments

Show parent comment

3

u/jshine13371 6 Jul 03 '26

A generalized statement which is inclusive of other things (not just CTEs) isn't the same as what you said "'CTE perform worse than subselect'". That's a more specific and drastic statement.

Regardless, as my edit points out, there are use cases where that's technically true.

1

u/Menthalion Jul 03 '26

I didn't say they did, just that people somehow still thought they do based on outdated SQL versions that didn't implement predicate & projection pushdown and sort elimination .

2

u/No_Resolution_9252 Jul 03 '26

Your quick google search didn't teach you what you needed to know on the topic. On the SQL Server side - SQL Server never supported CTEs without predicate pushdown and sort elimination - other than in columnstore, but columnstore was so horrible until SQL 2016, the applications for it were so limited its pretty unlikely there would have been a use case anyways.

Those optimizations or the lack thereof have nothing to do with why CTEs don't work in some cases.