SQL查询,关联查询的区别 (LEFT JOIN 、LEFT OUTER JOIN、INNER JOIN)

 

 

 1 CREATE TABLE #a(f1 VARCHAR(30),    f2 VARCHAR(40) )
 2 CREATE TABLE #b(f1 VARCHAR(30),    f2 VARCHAR(40) )
 3 ------------------------------------------------
 4 INSERT INTO #a(f1,f2)VALUES('1','a1')
 5 INSERT INTO #a(f1,f2)VALUES('2','a2')
 6 INSERT INTO #a(f1,f2)VALUES('3','a3')
 7 INSERT INTO #a(f1,f2)VALUES('4','a4')
 8 -------------------------------------
 9 INSERT INTO #b(f1,f2)VaLUES('1','b1')
10 INSERT INTO #b(f1,f2)VaLUES('2','b2')
11 --INSERT INTO #b(f1,f2)VALUES('3','b3')
12 --INSERT INTO #b(f1,f2)VaLUES('4','b4')
13 SELECT a.*,b.*
14 FROM #a AS a LEFT JOIN #b AS b ON a.f1 = b.f1
15 --
16 SELECT a.*,b.*
17 FROM #a AS a LEFT OUTER JOIN #b AS b ON a.f1 = b.f1
18 -----------
19 SELECT a.*,b.*
20 FROM #a AS a , #b AS b WHERE  a.f1 = b.f1
21 --
22 SELECT a.*,b.*
23 FROM #a AS a INNER JOIN #b AS b ON a.f1 = b.f1

 

posted @ 2018-03-15 17:22  蓝雨冰城  阅读(384)  评论(0编辑  收藏  举报