1719
submitted 10 months ago by tsuica@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] xmunk@sh.itjust.works 18 points 10 months ago* (last edited 10 months ago)

Sorry, to clarify, not everything is in all caps. I'll append my prefered syntax below

WITH foo AS (
    SELECT id, baz.binid
    FROM
            bar
        JOIN baz
            ON bar.id = baz.barid
)
SELECT bin.name, bin.id AS binid
FROM
        foo
    JOIN bin
        foo.binid = bin.id

The above is some dirt simple SQL, when you get into report construction things get very complicated and it pays off to make sure the simple stuff is expressive.

[-] NedDasty@lemmy.world 14 points 10 months ago

You indent your JOIN? Why on earth? It lives in the same context as the SELECT.

[-] xmunk@sh.itjust.works 9 points 10 months ago

I've seen both approaches and I think they're both quite reasonable. An indented join is my preference since it makes sub queries more logically indented... but our coding standards allow either approach. We've even got a few people that like

FROM foo
JOIN bar ON foo.id = bar.fooid
JOIN baz ON bar.id = baz.barid
[-] callcc@lemmy.world 6 points 10 months ago

Actually not. It's part of the FROM

[-] Stumblinbear@pawb.social 2 points 10 months ago

That double indented from is hurting me

[-] Cold_Brew_Enema@lemmy.world 1 points 10 months ago

Um you forgot the semicolon before with assuming there isn't one in the previous statement. Syntax error. Code review failed

[-] xmunk@sh.itjust.works 5 points 10 months ago

There's no way we're running in multi statement mode... I like my prepared queries, thank you very much.

this post was submitted on 19 Oct 2023
1719 points (98.8% liked)

Programmer Humor

31700 readers
579 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS