简体   繁体   English

什么是PostgreSQL中的LEFT JOIN

[英]What is a LEFT JOIN in PostgreSQL

I've seen a query using a LEFT JOIN as opposed to an INNER or LEFT OUTER . 我见过使用LEFT JOIN而不是INNERLEFT OUTER

What is a LEFT JOIN exactly? 什么是LEFT JOIN

Where an inner join returns only entries that match in both tables, a left join takes all the entries from first table and any that match in the second table. 如果inner join联接仅返回两个表中匹配的条目,则left join将获取第一个表中的所有条目以及第二个表中匹配的任何条目。 A right join is the reverse of a left join (ie: all from the second table) right joinleft join的反向(即:所有来自第二个表)

So if TableA is 所以如果TableA是

A B
1 a
2 b
3 c

and TableB is 和TableB是

A B
1 d
2 e

Then Select * from TableA inner join TableB on TableA.A = TableB.A returns 然后Select * from TableA inner join TableB on TableA.A = TableB.A返回

1 a 1 d
2 b 2 e

And Select * from TableA left join TableB on TableA.A = TableB.A returns 并且Select * from TableA left join TableB on TableA.A = TableB.A返回

1 a 1 d
2 b 2 e
3 c null null  

It is the same as LEFT OUTER (The OUTER is implied because an INNER JOIN requires bilateral matching so a LEFT INNER JOIN would make no sense). 它与LEFT OUTER相同(因为INNER JOIN需要双边匹配所以暗示OUTER,因此LEFT INNER JOIN没有意义)。 The same applies for RIGHT JOIN and FULL JOIN these are equivalent to RIGHT OUTER JOIN and FULL OUTER JOIN respectively 这同样适用于RIGHT JOINFULL JOIN它们分别相当于RIGHT OUTER JOINFULL OUTER JOIN

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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