Join的7中狀況

1、左外鏈接

  SELECT * FROM A LEFT JOIN B ON A.KEY = B.KEY

  

 

2、右外鏈接 

  SELECT * FROM A RIGHT JOIN B ON A.KEY = B.KEY

  

 

3、內鏈接 

  SELECT * FROM A INNER JOIN B ON A.KEY = B.KEY

  

 

4、全鏈接 

1  SELECT * FROM A FULL OUTER JOIN B ON A.KEY = B.KEY #Mysql不支持

  

 

2  SELECT * FROM A LEFT JOIN B ON A.KEY=B.KEY
   UNION
   SELECT * FROM A RIGHT JOIN B ON A.KEY=B.KEY

 

5、左鏈接

  SELECT * FROM A LEFT JOIN B ON A.KEY = B.KEY WHERE B.KEY IS NULL

   

 

6、右鏈接

  SELECT * FROM A RIGHT JOIN B ON A.KEY = B.KEY WHERE A.KEY IS NULL

   

 

7、全外鏈接

 1 SELECT * FROM A FULL OUTER JOIN B ON A.KEY = B.KEY WHERE A.KEY IS NULL OR B.KEY IS NULL #mysql不支持

   

  

2  SELECT * FROM A LEFT JOIN B ON A.KEY=B.KEY WHERE B.KEY IS NULL    UNION    SELECT * FROM A RIGHT JOIN B ON A.KEY=B.KEY WHERE A.KEY IS NULL
相關文章
相關標籤/搜索