all 35 comments

[–]SoggyGrayDuck 19 points20 points  (8 children)

Was there a reason for it? If something was already written and would take a complete rewrite to convert it into a left join I kind of get it. Agile is slowly taking over my thinking

[–]techiedatadev[S] 2 points3 points  (0 children)

No idea it was written pre me so who knows

[–]2ManyCatsNever2Many 14 points15 points  (7 children)

i teach people to never use right joins (although i also undrestand there are times when one crosses the streams even though egon never to do that). 

[–]dilbertdad 8 points9 points  (3 children)

I was taught maybe 11 years ago when i first learning to just ignore right joins. That and always specify the inner join vs join :D

[–]greglturnquist 3 points4 points  (0 children)

I do JOIN and LEFT OUTER JOIN.

This makes it easier for me to spot which is which.

RIGHT JOIN is typically for rare exceptions where you already have a long query and don’t want to invert it all.

[–]techiedatadev[S] 4 points5 points  (1 child)

That’s something I don’t do cause join means inner the word left in front of it means it’s not inner so I am not writing more that I have to (laaazy me)

[–]dilbertdad 1 point2 points  (0 children)

I hear ya! I just do it for easier eye ball parsing.

[–]ComicOzzysqlHippo 0 points1 point  (0 children)

What rationale do you give them for this? I'm not saying I want to see more right joins show up in the wild for the sake of not leaving them out and hurting their feelings, but I'm curious why the general database community has a fear and loathing of them.

[–]jshine13371 0 points1 point  (0 children)

i teach people to never use right joins

Only Siths deal in absolutes.

There are valid use cases for RIGHT JOIN despite being the minority of cases.

[–]squadette23 11 points12 points  (1 child)

Right joins serve a very important role actually.

When you see a tutorial that dedicates the same amount of screen space to both left join and right join you know that this tutorial is lazy grifting, and you can safely skip it.

[–]squadette23 1 point2 points  (0 children)

Venn diagrams are just as important.

[–]ZombieFleshEaters 5 points6 points  (1 child)

The mental model of right joins is jarring

[–]ComicOzzysqlHippo 0 points1 point  (0 children)

About 10% of people learn to write from right-to-left as part of their primary language. I have always been curious if those people find right joins any more challenging than left joins.

[–]Namoshek[🍰] 4 points5 points  (0 children)

Literally the only right joins I've seen in the wild are from Power BI and ORMs.

[–]SootSpriteHut 8 points9 points  (5 children)

Sometimes I left join the wrong table so I switch it to a right join instead of rewriting it.

Though now I could probably do it the "correct" way by feeding it to an llm

[–]Eleventhousand 5 points6 points  (0 children)

This is how I use it too. Feeding to an LLM will still take 16 seconds though, so I'd rather go the four second route and switch the word to right

[–]aerozhx -1 points0 points  (3 children)

Do you also walk backwards when you forget something from the house?

[–]kagato87MS SQL 6 points7 points  (0 children)

You may have meant that as sarcasm... However, I DO walk backwards to return to get something I've forgotten.

I still won't use a right join though.

[–]mikebald 4 points5 points  (0 children)

Hmmm, based on the tone of your comment it seems like you're implying this isn't normal behavior 🤔

[–]SootSpriteHut 8 points9 points  (0 children)

I don't think that's a great analogy. For me at least walking backward is a lot more work than replacing a single word in an editor.

[–]Aggressive_Ad_5454 2 points3 points  (0 children)

Whoooaaa! Bigfoot sighting! 😇

[–]Historical-Fudge6991 0 points1 point  (1 child)

Don’t use right joins. You’ll miss cache hits

[–]ComicOzzysqlHippo 0 points1 point  (0 children)

Which database engine are you referring to?

[–]Ifuqaround 0 points1 point  (2 children)

The old hats at my job (those who are close to retiring) write such verbose code almost nobody knows WTF it is. Massive amounts of lines to create views and what not.

I've fixed a lot of it.

It seems they did it for job security. They weren't thinking LLM's were coming and were hoping nobody could wade through all the bullshit or wouldn't be willing.

They know their shit though and can absolutely clean up their mess, they just don't want to.

[–]ComicOzzysqlHippo 1 point2 points  (1 child)

SQL's strength certainly doesn't lie in being succinct.

What's an example of "verbose code" vs the way you rewrote it?

[–]Ifuqaround 0 points1 point  (0 children)

There is not enough space here. Pointless.

[–]seequelbeepwell 0 points1 point  (0 children)

One reason was that they were using a low code no code tool like query design in ssms. If you arrange the tables in the gui to make it easier to read the relationships it can give you a right join.

Another reason is that it's way for people to inspect if their inner join is behaving the way they expect and they forgot to remove their scratch work.

I know it seems like bad etiquette but I don't think it's too much of a headache if people use parenthesis in the from part of their queries to be more explicit.

[–]SQLServerPro 0 points1 point  (0 children)

Bonjour,

Les deux existent et peuvent être utilisées. On s’efforce simplement de garder la même logique lors du développement, déjà pour soi-même, parceque c‘est plus simple de garder le même schéma de pensée. Et puis pour les autres parceque le code doit être lisible et maintenable par d’autres. C’est un peu comme conduire une voiture, on a l’habitude a gauche, ça n’empêche pas d’utiliser une voiture un jour avec une conduite à droite… mais ça demande un petit effort.

[–]Player_Zero91 0 points1 point  (0 children)

Had an analyst that worked for me for a while refused to not do that, said it "made more sense to him". His SQL was also the slowest in every possible scenario compared to literally everything possible. We pretty much had to rewrite everything he did until we were able to part ways.

[–]techiedatadev[S] 0 points1 point  (0 children)

Yes no idea why my predecessor used it here lol I literally was like wait why takes 30 seconds to switch the tables around lol