inner join与left join的区别 ---转载

inner join与left join的区别

转载于:https://www.cnblogs.com/alisonGavin/p/7338810.html

1. INNER  JOIN 产生的结果是AB的交集

SELECT * FROM TableA INNER JOIN TableB ON  TableA.id = TableB.rec_id

2. LEFT (OUTER) JOIN   产生表A的完全集,而表B中匹配的则有值,没有匹配的则以null值取代.

SELECT * FROM TableA LEFT OUTER JOIN TableB ON TableA.id = TableB.rec_id;

3.RIGHT(OUTER)  JOIN 产生表B的完全集,而表A中匹配的则有值,没有匹配的则以null值取代

SELECT * FROM TableA RIGHT   OUTER JOIN TableB ON TAbleA.id = TableB.rec_id

4. FULL (OUTER)   JOIN  产生A和B的并集,对于没有匹配的记录,以null值做为值

SELECT *  FROM TableA FULL OUTER JOIN TableB ON TableA .name = TableB.name

可以通过is null将 没有匹配的值找出来;

SELECT * FROM TableA FULL OUTER JOIN TableB ON TableA.name = TableB.name

WHERE TableA.id is null OR TableB.id is null

posted @ 2020-03-09 21:54  八风不动  阅读(208)  评论(0编辑  收藏  举报