简体   繁体   中英

Right join vs left join, which table is left vs right?

Given

select * 
from a
left join b
on a.id = b.id

is table a left and table b right?

Would that be equivalent to

Select *
from a
right join b
on b.id = a.id

because I switched left and right while flipping the ON clause? Or is a still left because it came first and b is right because it's the thing we're joining?

Thank you.

No. "left" and "right" refer to the ordering of the tables in the FROM clause. So these are equivalent:

select * 
from a left join
     b
     on a.id = b.id

select * 
from b right join
     a
     on a.id = b.id

These two on clauses do exactly the same thing:

on a.id = b.id
on b.id = a.id

They do not affect the results at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM