Subquery or CTE? Here’s How I Decide.
The simplest way to make your SQL cleaner, faster to debug, and easier to explain.
✨Your one-stop shop for cleaner queries, smarter dashboards, and fewer late-night Google searches:
The Data Analytics Stash ✨
If you’ve written SQL long enough, you’ve probably hit that moment where your query stops making sense halfway through.
You’re scrolling up and down, trying to remember which brackets belong together, and wondering if maybe Excel wasn’t so bad after all.
I used to write those kinds of queries too: one giant nested block that did technically work but terrified anyone (and my future self!) who had to read it later.
Then I started using common table expressions (CTEs).
And no, they don’t make your query faster. Performance is not that improved.
But they do make your queries readable.
In my latest post, I break down:
When to use a subquery vs. when to switch to a CTE.
What’s actually happening in the background.
And a few small readability habits that make your future self’s life easier.
If you’ve ever opened one of your own old queries and wondered, “Who the heck wrote this?”, this post will help.
Read it here:
P.S.: If you liked this post, you’ll probably like my SQL Best Practices Guide too.
It’s full of the little formatting habits and conventions that make your code easier to read, review, and explain, especially when someone asks you to “just make a quick change.”
Grab yours here!
Till next time,
— Sarah
Looking for Data Analytics Resources?
You’ll find them here:
📚 You Might Also Like...
Here are a few more blog posts you might be interested in:
30 Interview Questions to Prepare for Your Next Data Analyst Role
Learning New Data Skills While Working Full-Time: How to Make It Work
Building a Data Analytics Portfolio: What to Include and Where to Start
You Don’t Have to Be a Math Wizard to Work in Data Analytics
Let’s be LinkedIn buddies!
Want more data stuff between newsletters? I’m always on LinkedIn. Connect or follow me! I’m probably on there posting about something right now…
☕ Want to Support My Work?
If something I wrote helped you out, made you laugh, or saved you from rewriting the same SQL query five times… and you feel like sending a coffee my way, here’s where you can do that.
Totally optional. Always appreciated. :)
If you’re looking for more tips like this, I share regularly on my socials. Come and say hi 👋:
LinkedIn | Medium | Facebook | X (Twitter) | Pinterest
Thanks for reading!
—Sarah









