I have been asked in an interview that why we need left and right join separately while we can get same result by using any of them by changing the order of table? Please help me.
Asked
Active
Viewed 1,416 times
-1
-
You don't need both -- but would you rather make 3 lefts when 1 right turn can do? Just kidding of course, it's just standard sql. To each his own -- I prefer `left join` myself though. Others think "backwards" and prefer `right join`... – sgeddes Dec 10 '15 at 02:53
2 Answers
2
Technically, the language doesn't need both. In fact, I avoid right join
and see no issues at all. Left join
is preferable for two reasons. First, the logic is simpler to me -- keep all rows in the first table and then matching rows in the second and subsequent tables. More importantly, SQL queries are parsed left to right so:
from a left join b left join c
is parsed as
from (a left join b) left join c
If you work out some complex examples, you will see that this structure of parsing is more intuitive with left join
than right join
.
Of course, databases support both forms because the ANSI standard requires it. And, if some people have different preferences, they can use right join
as much as they want.

Gordon Linoff
- 1,242,037
- 58
- 646
- 786