r/SQL • u/BrilliantLeast7083 • Mar 25 '26
Discussion When to use RIGHT JOIN instead of switching tables in Left Join
Hello all! I need some help with understanding the utility of Right join. I have 2 tables: Orders and Customers. If I write Orders RIGHT JOIN Customers it returns the same results as switching tables and using left join, like Customers LEFT JOIN Orders. But when these 2 examples can give different results? Like when it is mandatory to use right join instead of just switching tables in left join?
35
Upvotes
View all comments
Show parent comment
1
u/jshine13371 Mar 26 '26
One example is when you're filtering the fully joined dataset that requires an
ORoperator in a predicate against theFULL JOINimplementation but can be rewritten as a separate predicate, for each of theUNIONed datasets, therefore improving sargability.There's more complex use cases I've encountered where generally re-writing as the
UNIONimplementation was more performant, but I don't recall the exact scenarios offhand.(Btw the
UNIONimplementation can be aUNION ALLdepending on the use case / context too.)