+ 2
What is the difference between the RIGHT JOIN and the LEFT JOIN?
I undertand the concept of each but I dont get why or when will I use one instead of the other. What I mean is... as I see, I can use: "table1 LEFT OUTER JOIN table2" and get the same result of "table2 RIGHT OUTER JOIN table1" Am I correct with this? So why do I need both functions? Thank you for your help and attention!
2 Respuestas
+ 2
There is no actual difference between RIGHT JOIN and LEFT JOIN, anything that can be done through LEFT JOIN, can be done through RIGHT JOIN just as well. In some cases, DBMS may not have RIGHT JOIN features at all.
In practice RIGHT JOIN is significantly less used then LEFT JOIN, but in theory having both makes you more flexible, and if you combine them, enables you to formulate queries more understandable.
0
Select * from Table1 left join Table2 ...
and
Select * from Table2 right join Table1 ...
are indeed completely interchangeable. Try however Table2 left join Table1 (or its identical pair, Table1 right join Table2) to see a difference. This query should give you more rows, since Table2 contains a row with an id which is not present in Table1.