inner join与left join的区别
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
转载: 2017年阿里内推题