阅读 31

Join的7中情况

一、左外连接

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

  

 

二、右外连接 

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

  

 

三、内连接 

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

  

 

四、全连接 

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

 

五、左连接

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

   

 

六、右连接

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

   

 

七、全外连接

 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

 

文章分类
代码人生
文章标签