1、内连接(自然连接): 只有两个表相匹配的行才能在结果集中出现
2、外连接: 包括
(1)左外连接(左边的表不加限制)
(2)右外连接(右边的表不加限制)
(3)全外连接(左右两表都不加限制)
3. 例子
a.txt
1 2 34 2 1
8 3 4
4 3 3
7 2 5
8 4 3
b.txt
2 48 9
1 3
2 7
2 9
4 6
4 9
LEFT JOIN
grunt> A = LOAD '/user/mypig/a.txt' AS(a1:chararray,a2:chararray,a3:chararray);
grunt> B= LOAD '/user/mypig/b.txt' AS(b1:chararray,b2:chararray);
grunt> C = JOIN A BY a1,B BY b1;
grunt> DUMP C;
结果:
(1,2,3,1,3)
(4,2,1,4,6)
(4,2,1,4,9)
(4,3,3,4,6)
(4,3,3,4,9)
(8,3,4,8,9)
(8,4,3,8,9)
LEFT OUTER:
grunt> C = JOIN A BY a1 LEFT OUTER,B BY b1;
grunt> DUMP C;
结果:
(1,2,3,1,3)
(4,2,1,4,6)
(4,2,1,4,9)
(4,3,3,4,6)
(4,3,3,4,9)
(7,2,5,,)
(8,3,4,8,9)
(8,4,3,8,9)