我正在重新发布我删除的先前问题的更清晰版本。
如下面的示例所示,我只想在' 的 id 没有出现在'列中时才table_b
合并。每个表对于它没有的任何字段都应该有一个空值。table_a
table_b
table_a
table_b_id
例子:
表_a
+----+-------+------------+
| id | name | table_b_id |
+----+-------+------------+
| 0 | mike | 1 |
+----+-------+------------+
| 1 | jack | 1 |
+----+-------+------------+
表_b
+----+-------+
| id | name |
+----+-------+
| 0 | tom |
+----+-------+
| 1 | joe |
+----+-------+
结果:
+-------------+-------+------------+
| original_id | name | table_b_id |
+-------------+-------+------------+
| 0 | mike | 1 |
+-------------+-------+------------+
| 0 | tom | |
+-------------+-------+------------+
| 1 | jack | 1 |
+-------------+-------+------------+