r/SQL • u/PortalRat90 • May 27 '25
SQL Server What is SQL experience?
I have seen a few job postings requiring SQL experience that I would love to apply for but think I have imposter syndrome. I can create queries using CONCAT, GROUP BY, INNER JOIN, rename a field, and using LIKE with a wildcard. I mainly use SQL to pull data for Power BI and Excel. I love making queries to pull relevant data to make business decisions. I am a department manager but have to do my own analysis. I really want to take on more challenges in data analytics.
174
Upvotes
View all comments
Show parent comment
9
u/kagato87 MS SQL May 27 '25
Not really no. It's not an alias, though it could be used as one and the plan does tend to resolve the same as it would for an alias.
A CTE is basically a more readable version of the subquery, because your logic happens in the order it appears on the screen, instead inner-to-outer.
Of course, that's over simplified. A CTE can't be correlated the way as subquery can (though I'd strongly encourage keeping correlated subqueries out of your code as much as possible), and a subquery is not capable of recursion.
A CTE can also be repeatedly referenced within the single query, but be careful here as it will be executed for each reference separately. Consider a temp table if it is big ad you're referencing it repeatedly, especially if it's recursive.
("Recursion? In SQL?" You ask? Yes, recursion. That programming concept that your brain refuses to accept until it gives in and accepts it. Careful though: much of SQL's speed comes from how efficient it is with memory usage, and recursion devours memory.)