MySQL七種join舉例
阿新 • • 發佈:2021-02-03
技術標籤:mysql
一、左外連線
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
四、左連線
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
六、全連線
- Mysql不支援下列方式
SELECT * FROM A FULL OUTER JOIN B ON A.KEY = B.KEY
- Mysql支援下列方式
SELECT * FROM A LEFT JOIN B ON A.KEY=B.KEY
UNION
SELECT * FROM A RIGHT JOIN B ON A.KEY=B.KEY
七、全外連線
- mysql不支援下列方式
SELECT * FROM A FULL OUTER JOIN B ON A.KEY = B.KEY WHERE A.KEY IS NULL OR B.KEY IS NULL
- mysql支援下列方式
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