---
title: "MySQL全连接(Full Join）实现 "
author: "libin123"
date: "2012-07-09T18:18:06Z"
tags: []
categories: ["数据库"]
slug: "mysql-full-join"
draft: false
lastmod: "2012-07-09T18:18:58Z"
id: 1583173
url: "https://dbua.iteye.com/blog/1583173"
---

MYSQL 可以用 union 实现全连接
mysql> select * from a;
+------+
| id   |
+------+
|    1 |
|    2 |
|    3 |
+------+
3 rows in set (0.00 sec)

mysql> select * from b;
+------+
| id   |
+------+
|    1 |
|    2 |
|    4 |
+------+
3 rows in set (0.00 sec)

mysql> select a.id,b.id from a left join b on a.id=b.id union select a.id,b.id f
rom a right join b on a.id=b.id;
+------+------+
| id   | id   |
+------+------+
|    1 |    1 |
|    2 |    2 |
|    3 | NULL |
| NULL |    4 |
+------+------+
4 rows in set (0.00 sec)

mysql>