What is the use of a left join(or for that matter maybe even inner join) if one can simply write a full outer join like so
playorm=# select * from trade as a full outer join Account as b on b.id=a.accoun
tid where a.id = a.id;
This ends up returning all the same results an LEFT inner join would return.
or if you want an inner join, you can do this
playorm=# select * from trade as a full outer join Account as b on b.id=a.accoun
tid where a.id = a.id AND b.id = b.id;
This ends up returning all the same results an INNER JOIN would return.
I just thought this was kind of interesting is all I guess. I originally mistaking thought a left outer join would return nulls + what the conditions matched but found out the conditions have to match which is kind of weird as in this inner join eliminates records that match(probably because join is done before expression matching so the a.accountid is null is a useless part of the where clause…
select * from trade as a inner join Account as b on b.id=a.accountid
here (b.isActive=false OR a.accountid is null) and a.number < 15;
later,
Dean
I’m not quite sure of the intent of your question. Do you mean “Why does SQL support syntax for left-outer-join when it’s easy to use syntax for full-outer-join with an extra xxx is not null condition?” In other words, does left-outer-join appear to be unnecessary syntactic sugar?
Answer: You use syntactic sugar to make your meaning clearer to someone else who reads your code. For example imagine a school has a table of students and a table of courses. If you want to see a list of students and what courses they have passed, including students who have not passed anything, then left outer join makes that intention clear. If I see a full outer join in your code, I might assume you are also interested in courses that nobody has passed. It would take a little digging into your code to find that clause among the conditions that filters out those non-matching courses.
Programmers like me are often time-squeezed so they won’t dig into your code as deeply as might be ideal, so please give hints to help us understand your intent. Use synactic sugar to sweeten the professional lives of your colleagues.
By the way, you state that “inner join eliminates records that match”. Don’t you mean that “inner join eliminates records that do not match in the other table”? Actually, you are better off to think of inner join as returning all matching records, and left/right/full outer joins as supplementing the innner join with non-matched records from the first/second/both tables.