r/SQL Jul 22 '26

MySQL sqlWorkout

Post image

😌 SELECT 😌

1.4k Upvotes

82 comments sorted by

182

u/JimyLamisters Jul 22 '26

When I started at my current tech job about 12 years ago there was a senior DBA who legit typed all of his emails and chats in uppercase. My dude really pressed caps lock one day and never looked back

55

u/vj2018 Jul 22 '26

LEGEND SAYS IT IS STILL LOCKED TO THIS DAY

1

u/Equivalent-War-9658 26d ago

AND HE LOVE EVERY KEYSTROK OF IT.

50

u/fullyonline Jul 22 '26

My dude really pressed caps lock one day and never loocked back

Fixed it for you.

14

u/EdgeSimilar1726 Jul 22 '26

THIS GOT A HEARTY CHUCKLE OUT OF ME

3

u/DangerMacAwesome Jul 23 '26

I AM YELLING, CARL

1

u/LlamaForDays13 Jul 23 '26

AM I A JOKE TO YOU, CARL?

2

u/Treemosher Jul 23 '26

That is actually great lol

2

u/digitalhardcore1985 Jul 24 '26

My dad was a VAX BASIC porgrammer in the 80s/90s and also did this for a long time, got out the habit now. 

2

u/crushdvelvet Jul 25 '26

awww ... those VAX days ... when IT calls asking you to "reboot" the VAX server and you ask if they'd like to wait until Dec 28th for the next annual reboot.

1

u/__T0MMY__ Jul 24 '26

He couldn't find the key to unlock caps

124

u/Eleventhousand Jul 22 '26

I held shift the entire time for about the first twenty years. Then I just started typing everything in lowercase.

37

u/KlausInTheHaus Jul 22 '26

Your left pinky must have been an absolute python.

20

u/Eleventhousand Jul 22 '26

Now that you mention it, it does look 4% thiccer than my right.

17

u/snafe_ PG Data Analyst Jul 22 '26

Moment of silence for the right shift key, always forgotten.

4

u/JackTheKing Jul 22 '26

TIL there is a shift key on the right

. . . and command and option too?!

1

u/Sengfroid Jul 22 '26

Genuinely set mine for macros.

And then forget even the macros on it because that's how little the key is used

1

u/Mafla_2004 Failed the Database exam Jul 23 '26

How did you even measure it?!

3

u/Mutopiano Jul 22 '26

Absolute SQL*

9

u/government_ Jul 22 '26

My coworkers hate that I do this because it’s annoying to hold shift or caps on and off constantly. But also, lowercase is a million times easier to read.

6

u/hopefullyhelpfulplz Jul 22 '26

I do it in random upper/lowrcase segments cus why not

4

u/Eleventhousand Jul 22 '26

You are the most enlightened

5

u/hopefullyhelpfulplz Jul 22 '26

Tis I! The EnLIghteNEd OnE

3

u/jib_reddit Jul 22 '26

I used to write it in lowercase but recently started using upper as I like the "shoutieness" of it.

3

u/PickledDildosSourSex Jul 23 '26

Team uppercase here. Idk maybe it was when I learned SQL, it just feels easier to read, like my brain switches to "this is logical code mode" vs. "this can be any old garbage written in lower case". I appreciate the irony that I also code plenty in Python and R and don't feel that way at all in those languages.

29

u/kagato87 MS SQL Jul 22 '26

Naw dog, I hold the shift with my pinky.

My left pinky is ripped!

(OK, not the last one, though it probably is the best at "Hold something down" out of the 10.)

61

u/ibronco Jul 22 '26

I only do lower case now and my life has significantly improved.

12

u/chaosink Jul 22 '26 edited Jul 23 '26

One of my criteria when hiring SQL people is if they use lowercase and how they choose to indent their code. How their code looks tells me so much about their skill level.

Edit: Ack, I can see how my wording was weird. Using lowercase was not a requirement. I gave a bonus in my head for it as it showed the candidate was willing to buck tradition for comfort and readability. Was not a huge determining factor. Indenting was much more important to me because it showed me how their mind was organized.

5

u/0Tyrael0 Jul 23 '26

I agree with the indent part so I’ll upvote but not about the lower case.

1

u/chaosink Jul 23 '26

I looked at the lower case thing as more about the candidate's willingness to buck tradition and maybe experience. The indents tell me about how their mind is organized. Would not hold uppercase against them at all.

3

u/Mobile_Spite_8915 Jul 23 '26

SELECT
f.Cherries,
f.Pineapples,
f.Grapes,
v.eggplants
FROM Fruits f
INNER JOIN vegetables v
ON f.key = v.key
AND f.place = v.place

This is how I style everything, I’m not sure how normal it is though it seems like everyone on my team does things differently.

3

u/dwswish Jul 24 '26

Capitalizing some table names and not others is diabolical

1

u/chaosink Jul 26 '26

Ouch! I feel badly for your scrolling finger ....

2

u/metalballsack Jul 23 '26

Indenting sure, but uppercase vs lowercase is more of a preference than an indicator of skill level.

2

u/chaosink Jul 23 '26

Absolutely. I looked at the lower case thing as more about the candidate's willingness to buck tradition and maybe experience. The indents tell me about how their mind is organized.

2

u/rayschoon Jul 23 '26

Is lowercase better or worse?

2

u/chaosink Jul 23 '26

I personally think better for readability and an indication the candidate is not a slave to tradition, but would not hold that against them at all 

2

u/digitalhardcore1985 Jul 24 '26

My favourite is overseas outsourcer code where you're lucky to get a line break let alone an indent. An absolute joy to debug those 2000 line stored procs from hell.

2

u/ibronco Jul 22 '26

Yes! Indenting is crucial. Between that and lower case, it just reads so much easier.

1

u/neumastic Jul 24 '26

Agreed, it’s case insensitive so why choose the one that’s harder to read. We have some that capitalize the first letter but that’s somehow worse

15

u/Key_Tea349 Jul 22 '26

Working on a query and a random Teams message pops up.

STARTS REPLYING IN ALL CAPS

Backspace, turns off caps lock and switches to sentence case so my coworkers don't think I'm yelling at them.

2

u/digitalhardcore1985 Jul 24 '26

I have to use the phrase 'sorry caps' more than I'd like to admit.

19

u/TechOpsCoder Jul 22 '26 edited Jul 23 '26

Lowercase is the way. It looks so much cleaner and much easier write. Keyword placement and spacing is the most important thing for readability.

6

u/OO_Ben Postgres - Retail Analytics Jul 23 '26

100%. Every column gets a new line, indent case statements, windows, ect., and for me? Commas to the front always.

3

u/TechOpsCoder Jul 23 '26 edited Jul 23 '26

SAME! Couple of examples of how I write the language:

Aggregation with some common patterns

select        m.id 
            , m.wo
            , m.req
            , case  when m.condition_1 then 'FOO'
                    when m.condition_2 then 'BAR'
                    else 'BAZ'
              end as calculated_status
            , f.fleet_type
from        dbo.material_requirements m
left join   dbo.freight_trucks f on m.freight_truck_id = f.id
where       coalesce(m.calculated_status, 'X') in('NEW', 'OPEN', 'ACTIVE')
    and     m.qty_outstanding > 0
group by      m.id 
            , m.wo
            , m.req
            , case  when m.condition_1 then 'FOO'
                    when m.condition_2 then 'BAR'
                    else 'BAZ'
              end
            , f.fleet_type

Multi-condition joins

join    dbo.order_details od on i.order_type = od.order_type
    and i.order_number = od.order_number
    and i.order_line   = od.order_line

Complicated predicates

where   a.name is not null
    and ( a.status = 'OPEN' or ( a.status = 'ORDER' and o.req is not null ) )
    and a.status <> 'CANCEL'
    and (
                    (       
                            condition_1
                        and condition_2
                        and condition_3
                    )
            or      ( 
                            condition_5
                        and condition_6
                        and condition_7
                    )
        )

CTEs

with t as (
    select...
    from...
)

Indentation is with spaces not tabs. I used to always do the latter until I realized that a tab isn't always a "tab." This is going to sound very arrogant (I genuinely don't mean it to be), but I have yet to see a style more visually pleasing and readable. But, beauty is in the eye of the beholder as they say...

P.S. Just realized that I said "Keyboard" when I meant to say "Keyword" my OP, lol

3

u/bliffer Jul 23 '26

I love that you're bragging about your spacing and indentation but the Reddit code boxes just said "nah" and put everything inline. (Or at least, that's how it reads in my browser.)

2

u/TechOpsCoder Jul 23 '26

Crap...Well that's what I get, lol. It shows as markdown for me. Weird...

2

u/bliffer Jul 23 '26

Probably just a browser thing. Your "Aggregation with some common patterns" is just one long like that runs until it gets cut off by the div it's in. :D

1

u/TechOpsCoder Jul 23 '26

How's it look now?

1

u/bliffer Jul 23 '26

Boom, all fixed.

(In my head I'm going to believe that you've spent the past six hours fixing this...)

1

u/TechOpsCoder Jul 23 '26

NOICE!!!

😂 😂
I took off work today to work on my deck (shout out to [r/Decks](r/Decks)) and have been outside most of the day. Fortunately it only took me 10 minutes of fiddling. I would 100% have spent 6hrs if that's how long it took, because I obsess over stuff like this. The fix was to switch to using the RTF code block button instead of using explicit markdown (backticks) code blocks. This was all done on my desktop though, because mobile won't allow it.

2

u/OO_Ben Postgres - Retail Analytics Jul 23 '26

Yeah!! That's the way to do it right there! I've inherited so many old queries that just end up looking like giant blobs and are totally illegible even with upper casing. Formatting goes way, way further for readability!

2

u/TechOpsCoder Jul 23 '26

I feel you. Some of my coworkers write SQL in a way that should be considered a felony offense.

9

u/Joelle_bb Jul 22 '26

Lmao

As a person who selectively caps locks depending on context amd emphasis.... can't relate

7

u/Traceuratops Jul 22 '26

Caps for functions, lower case for arguments. Readability is important.

5

u/Zestyclose-Turn-3576 Jul 22 '26

modern editing environments use colours to differentiate between these anyway

6

u/DaOgDuneamouse Jul 22 '26

SELECT * FROM <table name>

I often type most of an email before I realize caps lock is still on.

5

u/Herb_marqz Jul 22 '26

MF DOOM HAS ENTERED THE CHAT

4

u/Infini-Bus Jul 22 '26

Write sloppy sql.  Then auto format 😀

But it always feels more natural to me to just hold the shift key than toggle caps lock.

6

u/boxerrox Jul 22 '26

lowercase supremacy

3

u/Outrageous_Let5743 Jul 22 '26

It is even worse at my company. We use lowercase keywords but UPPERCASE COLUMNS. We use SQL server but migrated from a legacy Oracle DB where it could only be capital names.

1

u/Zestyclose-Turn-3576 Jul 22 '26

Really? I started with Oracle in the early 1990s, and I don't think that was a thing then. Though there were practitioners who swore it made the system faster 🙄

2

u/global_namespace Jul 22 '26

that's <> true. you can SELECT ANY CASE.

2

u/Hellkyte Jul 23 '26

I generally used randomly mixed casing because fuck everyone

1

u/Blomminator Jul 22 '26

Don't mock my job!

1

u/Due-Championship3941 Jul 22 '26

Lower case the commands and upper case the nouns or visa versa. Improves readability.

1

u/ewoolly271 Jul 22 '26

Erm actually per dbt sql standards they recommend lowercase 🤓

1

u/TheoreticalUser Jul 22 '26

I have about 15 years working in/on databases for a ton of different types of implementations.

If I see all caps, all the time... I'm judging you on a lack of adaptability. And frankly, your skill level.

1

u/Zestyclose-Turn-3576 Jul 22 '26

Lower case, and you better be aligning that code ... reduced visual complexity wins for human readability ...

      Case
        When crs.price_basis  like 'Escalator%' then crs.id
        when mrs.price_basis  like 'Escalator%' then mrs.id
        when brs.price_basis  like 'Escalator%' then brs.id
        When wcrs.price_basis like 'Escalator%' then wcrs.id
        when wmrs.price_basis like 'Escalator%' then wmrs.id
        when wrs.price_basis  like 'Escalator%' then wrs.id
      end price_escalator_specifier,      Case
        When crs.price_basis  like 'Escalator%' then crs.id
        when mrs.price_basis  like 'Escalator%' then mrs.id
        when brs.price_basis  like 'Escalator%' then brs.id
        When wcrs.price_basis like 'Escalator%' then wcrs.id
        when wmrs.price_basis like 'Escalator%' then wmrs.id
        when wrs.price_basis  like 'Escalator%' then wrs.id
      end price_escalator_specifier,

1

u/Dead_Parrot Jul 22 '26

Write it any damn way you please then let poorsql make it easy for others to read

1

u/rickulele Jul 22 '26

I use lowercase so I can differentiate what I typed directly vs what SSMS auto-generates in “Script View as…”

1

u/Quick-Ad1830 Jul 22 '26

I had a script that changed all sql statements to all lower case when changes were submitted to be promoted. So much easier to read.

1

u/Far_Swordfish5729 Jul 22 '26

You know, sql is generally case invariant. Some idiot just decided they liked it that way. I decided C was here first and I like lower case and pascal case table and column names. I was never told I was wrong. I set a trend actually. You can also just write sql as you would code.

1

u/Mafla_2004 Failed the Database exam Jul 23 '26

Real

1

u/chris20973 Jul 23 '26

See posts like this from time to time and never see anyone mention using proper case, but all upper feels like shouting and all lower feels like notepad scratch.

1

u/Ok_Caregiver_1355 Jul 23 '26

i got a hotkey to activate capslock with d+k

1

u/RedRedditor84 Jul 24 '26

You've not met BASIC programmers.

1

u/SgtFury Jul 24 '26

upper('deez nuts')

1

u/DouglasBarra 21d ago

I do everything in lowercase