this post was submitted on 19 Nov 2025
444 points (93.0% liked)

Programmer Humor

27853 readers
748 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] saltesc@lemmy.world 22 points 3 weeks ago* (last edited 3 weeks ago) (17 children)

SQL enjoyer?

Every time I use it I feels like I'm going back to the 90s. No variables, no functions; Oh but you can do a CTE or subquery.......๐Ÿ‘

UNION ALL, UNION ALL, UNION ALL... "There's got to be a better way, surely..."

looks up better way

"Oh, what the fuck?!.... Nope, this will just be quicker..." UNION ALL, UNION ALL, UNION ALL...

Join in a table sharing column names... Everything breaks. You gotta put the new prefixes in front of all the headers you called in now. In every select, in every where, etc... Which is weird because that kinda works like a variable and it's fine...

"When you see this little piece of text, it means all this, got it?"

"Okay. Yep. Easy."

"So why can't you do that with expressions?"

SQL SCREAMS MANICALLY

"Okay, okay, okay!... Jesus..."

And then you try put a MAX in a where and it won't let you because you gotta pull all the maxes out in their own query, make a table, join them in, and use them like a filter...

I hate it. It has speed, when you can finally run the script, but everything up to that is so...ugh.

[โ€“] Valmond@lemmy.world 2 points 3 weeks ago (8 children)

LEFT JOIN

Includes empty entries, doubles others.

...

It sure is long due for an overhaul.

[โ€“] expr@programming.dev 5 points 3 weeks ago (1 children)

That's the whole point of a left join? Anything else wouldn't be a left join anymore.

[โ€“] Valmond@lemmy.world 1 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Well I didn't expect doubles. I'm sure not an expert.

[โ€“] expr@programming.dev 5 points 3 weeks ago (1 children)

It doesn't arbitrarily double rows or something. For each row in the relation on the left of the join, it will produce 1 or more rows depending on how many rows in the relation on the right of the join match the join condition. The output relation of the join may have duplicate rows depending on the contents of each joined relation as well as what columns you are projecting from each.

If you want to remove duplicates, that's what DISTINCT is for.

[โ€“] Valmond@lemmy.world 1 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Thanks, I will kot forget that the next time I have to do SQL!

Still wild there are no simpler language that have grown in popilarity for databases though.

[โ€“] expr@programming.dev 5 points 3 weeks ago (1 children)

To be honest, it's remarkably simple for what it's doing. There's a ton of details that are abstracted away. Databases are massively complex things, yet we can write simple queries to interact with them, with semantics that are well-understood and documented. I think, like anything else, it requires a bit of effort to learn (not a lot, though). Once you do, it's pretty easy to use. I've seen many non-technical people learn enough to write one-off queries for their own purposes, which I think is a testament to its simplicity.

[โ€“] Valmond@lemmy.world 1 points 3 weeks ago (1 children)

Oneliners are simple I give that to you, but then you have those incomplete tables and whatnot. Like take all entries from A and join B on A.id and B.id, set the result to some default if B doesn't exist.

You are surely going to whip up a perfect string of SQL but I'd struggle.

[โ€“] expr@programming.dev 1 points 3 weeks ago* (last edited 3 weeks ago) (1 children)

Heh yeah that's pretty straightforward:

SELECT a.*, COALESCE(b.some_col, 'some_default_val') as b_result
FROM a LEFT JOIN b ON (a.id = b.id);

This will produce at least 1 row for every row in a, and if a.id doesn't match any b.id, the value of b_result will be 'some_default_val'.

Not sure if that's exactly what you were describing (since it was a little ambiguous), but that's how I interpreted it.

Ultimately it's just a matter of investing a little time to learn it. It's not fundamentally difficult or complex, even though you certainly can write very complex queries.

[โ€“] Valmond@lemmy.world 1 points 3 weeks ago* (last edited 3 weeks ago)

You make me think of that xkcd with two mineral experts, wildly overestimate what ordinary people know about their speciality ๐Ÿ˜…

I have to do something like that sql like once every 2 years, so I tend to not invest enough, and then forget how it works. Give it some iterations and maybe I'll be OK one day!

Thanks for the solution!

Edit only found the meme template:

So you have to insert yourself: SQL, database specialist, SELECT, JOINS, COALESCE

load more comments (6 replies)
load more comments (14 replies)