我有两个要加入MySQL的表:



select TableA.*, TableB.Reason from TableA
left outer join TableB;
 





我的原始表是这样的:



Table A
-----+--------+-------+
| ID | Contact| Reason|
+----+--------+-------+
|  1 | Phone  |       |
|  2 | Mail   |       |
|  3 | Web    |  Info |

Table B
-----+-----------+
| ID | Reason    |
+----+-----------+
|  1 | Complaint |
|  2 | Info      |
|  3 |           |





我正在得到这个



-----+--------+-----------+---------+
| ID | Contact| Reason    | Reason  |
+----+--------+-----------+---------+
|  1 | Phone  |           |Complaint|
|  2 | Mail   |           | Info    |
|  3 | Web    | Info      |         |





但我期望这样:



-----+--------+-----------+
| ID | Contact| Reason    |
+----+--------+-----------+
|  1 | Phone  | Complaint |
|  2 | Mail   | Info      |
|  3 | Web    | Info      |  





我该怎么做呢?

最佳答案

采用

select TableA.ID, TableA.Contact, TableB.Reason from TableA
left outer join TableB;

关于mysql - 连接具有相同字段的两个表并将数据合并到一个字段中(MySQL),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44675236/

10-11 11:09