Mysql七种 JOIN 连接
Posted zhaye
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql七种 JOIN 连接相关的知识,希望对你有一定的参考价值。
内连接
SELECT <select_list> FROM TableA A INNER JOIN TableB B ON A.Key = B.Key
左外连接
SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key
SELECT <select_list> FROM TableA A LEFT JOIN TableB B ON A.Key = B.Key WHERE B.Key IS NULL
右外连接
SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key
SELECT <select_list> FROM TableA A RIGHT JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL
全外连接
mysql不支持,需要用union
SELECT <select_list> FROM TableA A FULL OUTER JOIN TableB B ON A.Key = B.Key
SELECT <select_list> FROM TableA A FULL OUTER JOIN TableB B ON A.Key = B.Key WHERE A.Key IS NULL OR B.Key IS NULL
以上是关于Mysql七种 JOIN 连接的主要内容,如果未能解决你的问题,请参考以下文章