Why can't we use left outer join replacing tables instead of right external join?

A few days ago, I came across a question in an interview as follows. "What is a right outer join?" I replied: "A direct outer join joins two tables and returns consistent records from both tables, as well as non-matching rows from table A." the interviewer simply laughed and asked again: “Why do we use Right join, can we swap tables and use left join?”. Then my answer was "yes, we can use." But he argued that "then why the concept of two unions (left and right)." I was really confused by this question. Please help me with this and correct my understanding of joins.

+4
source share
2 answers

LEFT [OUTER] JOIN RIGHT [OUTER] JOIN , .

, :

A LEFT  JOIN B ON A.X = B.Y
B RIGHT JOIN A ON A.X = B.Y
A LEFT  JOIN B ON B.Y = A.X -- switched A.X = B.Y around
B RIGHT JOIN A ON B.Y = A.X

.

.

:

, :

Right join, ?

:

Left join. , SQL , RIGHT , LEFT.

. LEFT RIGHT , , .


, . , .. , -, . - , , .

, - . . - , . , , , , , . , , , , .

+3

- / . , ( ): , ANSI.

. , LEFT OUTER JOIN, , . SQL Server showplan RIGHT OUTER JOIN (http://msdn.microsoft.com/en-us/library/ms190390.aspx). , . 1) , , 2) ANSI SQL. Theres , SQL Server, SQL Server - . , RIGHT OUTER JOIN LEFT OUTER JOIN, SQL SQL Server , . - , , , :)

, , , SELECT * FROM a, b, c, d WHERE (a.id = b.a_id b.a_id IS NULL) , ANSI- SQL.

0

All Articles