The only type of connection you really need is LEFT OUTER JOIN . Each other type of join can be rewritten in terms of one or more left outer joins and possibly some filtering. So why do we all the rest? Is it just confusing people? Wouldn't it be easier if there was only one type of connection?
You may also ask: why is there a <= b and b >= a ? Don't they do the same? Can't we get rid of one of them? This will simplify the situation!
It is sometimes easier to exchange <= on >= instead of replacing the round arguments. In the same way, the left join and the right join are the same thing, only with the replacement of operands. But then again, itβs practical to have both options instead of requiring people to write their requests in a specific order.
One more thing you could ask: logical, why do we have AND , OR , NOT , XOR , NAND , NOR , etc.? All this can be rewritten in terms of NAND s! Why not just NAND ? Well, itβs inconvenient to write OR in terms of NAND s, and itβs not so obvious that the intention is that if you write OR , people immediately understand what you mean. If you are writing a bunch of NAND s, it is not clear what you are trying to achieve.
Similarly, if you want to make a FULL OUTER JOIN b , you can make a left join and a right join, remove duplicate results, and then merge everything. But this is pain, and therefore there is a contraction for her.
When do you use each of them? Here's a simplified rule:
- If you always want a row of results for each row in the LEFT table, use the LEFT OUTER JOIN.
- If you always want to get a row of results for each row in the RIGHT table, use the CORRECT EXTERNAL JOINT.
- If you always need a row of results for each row in any table, use FULL OUTER JOIN.
- If you only need a row of results when there is a row in both tables, use INNER JOIN.
- If you need all possible pairs of rows, one row from each table, use CROSS JOIN.
Mark byers
source share