this post was submitted on 15 Feb 2024
122 points (96.9% liked)

Programming

17416 readers
37 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
top 14 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 9 months ago

CTEs are amazing. I discovered them semi recently and it's such a great tool to have in your belt.

Partitioning is definitely something I need to work on.

[–] [email protected] -2 points 9 months ago (1 children)

I have to create a fucking account just to fucking read your article?! Kthxbye!

[–] [email protected] 12 points 9 months ago (1 children)
[–] [email protected] 2 points 9 months ago

Lol

But just that popup existing is irritating.

[–] [email protected] 12 points 9 months ago

CTEs enhance readability, documentation, and testing imo. I'm very pro CTE whenever a subquery isn't the obvious choice.

[–] [email protected] 4 points 9 months ago

Very useful. I'll definitely going to use the ranking stuff.

[–] [email protected] 9 points 9 months ago

It's always bothered me when I write subqueries that have to be run on each row. Good to know that there's a better way.

[–] [email protected] 16 points 9 months ago (1 children)

I feel like the word "partitions" used in this article should be "window functions"

[–] [email protected] 3 points 9 months ago

Good point. Window functions are mandatory knowledge for intermediate users

[–] [email protected] 22 points 9 months ago* (last edited 9 months ago) (2 children)

Stage 5 can give you a huge boost in writing complex queries!

You say that like it's a good thing. I like my queries simple.

Also - the stuff you have under "stage 6" should all be learned before "stage 2" in my opinion. Knowing how to write efficient queries is far more important than group by / join / etc.

[–] [email protected] 3 points 9 months ago* (last edited 9 months ago)

Joining is one of the simplest and most useful things in SQL.

How can you possibly query without it?

Simple queries are obviously better but not everything can be achieved with simple selects.

[–] [email protected] 13 points 9 months ago (1 children)

Huh? How do you write an efficient query and not take into account joins? A single table query? Are you a Prisma fan?

[–] [email protected] 8 points 9 months ago

Are you a Prisma fan?

Ooooh, that's a good burn

[–] [email protected] 15 points 9 months ago

I imagine it depends on use case. Anything more advanced that subqueries/CTEs is largely the domain of ETL developers (not exclusively, obviously) but most others using SQL don't need anything that advanced.