如果任何列值为 NULL,SQLite 的 Natural Join 会从两个表中排除相同的匹配项。
给定表格:
+----------------------------------------+
| 员工 |
+----------------------------------------+
| 员工编号 | 工作ID | 部门ID |
+-------------+--------+----------------+
| 1 | 空 | 10 |
+-------------+--------+----------------+
| 2 | 空 | 20 |
+-------------+--------+----------------+
| 3 | "id3" | 30 |
+-------------+--------+----------------+
和:
+----------------------------------------+
| 工作历史 |
+----------------------------------------+
| 员工编号 | 工作ID | 部门ID |
+-------------+--------+----------------+
| 1 | 空 | 10 |
+-------------+--------+----------------+
| 2 | 空 | 20 |
+-------------+--------+----------------+
| 3 | "id3" | 30 |
+-------------+--------+----------------+
| 4 | "id4" | 40 |
+-------------+--------+----------------+
select * from employees natural join job_history
结果:
+-------------+--------+----------------+
| 2 | 空 | 20 |
+-------------+--------+----------------+
| 3 | "id3" | 30 |
+-------------+--------+----------------+
select * from employees intersect select * from job_history
结果:
+-------------+--------+----------------+
| 1 | 空 | 10 |
+-------------+--------+----------------+
| 2 | 空 | 20 |
+-------------+--------+----------------+
| 3 | "id3" | 30 |
+-------------+--------+----------------+