winbacker
winbacker

Reputation: 627

In SQL outer joins, what part of the query puts a table on the "left" or "right"?

I am reading books on outer joins and they reference the "position" of a table in determining whether all of its records will be displayed.

I am confused about how exactly the position (left/right) is determined?

If we consider the standard SQL join

Select * FROM
Table_A left outer join Table_B
on Table_A.ID = Table_B.Product_ID

What part of this query is determining the position of each Table?

Is it the join part:

Table_A left outer join Table_B

Where Table_A is on the "left" because it is left of the join word?

Or is it the "=" part:

on Table_A.ID = Table_B.Product_ID

Where Table_A is on the "left" because it is left of the "=" sign?

Upvotes: 2

Views: 92

Answers (2)

HaveNoDisplayName
HaveNoDisplayName

Reputation: 8497

This makes the difference, so Table name on left side of LEFT OUTER JOIN is leading one

Table_A left outer join Table_B

As per the MSDN, left outer joins include all of the records from the first (left) of two tables, even if there are no matching values for records in the second (right) table.

Upvotes: 4

Frank V
Frank V

Reputation: 25419

It's the relative position of the table name in the SQL.

table1 left join table2  

means table 1 is the principle table, where as in a right join the table2 would be the principle table.

Upvotes: 0

Related Questions