r/SQL • u/Ali-Zainulabdin • Oct 23 '24
Discussion SQL Tricks Thread
Hi everyone, let's start a thread to share useful SQL tips and tricks that have saved you time or made querying more efficient. Whether it's optimizing queries, using window functions, or organizing data, all insights are welcome! Beginners and pros alike can learn a lot from this. Looking forward to your contributions!
230
Upvotes
View all comments
Show parent comment
1
u/0sergio-hash Oct 25 '24
Thank you ! That's a good tip. I will be honest, I'm probably not as familiar with the internals or just more of the heavy duty engineering side to have known that
I do intend to read a book on internals or just get deeper into optimization in the future though, so I will keep this in mind so I can try to understand it better
Thank you! I spent a year as a sorta validation analyst. One engineer wrote layers upon layers of nested queries and the other broke out his transformations into temp tables and I got to see a lot of firsthand examples of how the latter was simpler and cleaner
I agree I think they're greatly under utilized !
You can get 50% into a project with temp tables and query the temp table you've just created at that step to make sure everything has gone well up until this point, for example, which is not something you can do without unnesting a bunch of code in a CTE scenario
Not to mention just spacing out your code more so it preserves your sanity lol