在Mysql中连接表以保持多个观察值
我有表1和表2,它们可以在ID上连接。有什么方法可以得到最终的表吗?谢谢 表1:在Mysql中连接表以保持多个观察值,mysql,Mysql,我有表1和表2,它们可以在ID上连接。有什么方法可以得到最终的表吗?谢谢 表1: ID ProcCode 1 a 2 b 表2: ID DiagCode ICode 1 z g 1 z g 1 x g 最终表格: ID ProcCode DiagCode ICode 1 a z g 1 a z g 1 a x g 2 b NULL
ID ProcCode
1 a
2 b
表2:
ID DiagCode ICode
1 z g
1 z g
1 x g
最终表格:
ID ProcCode DiagCode ICode
1 a z g
1 a z g
1 a x g
2 b NULL NULL
是的,使用
左外连接
select t1.ID,
t1.ProcCode,
t2.DiagCode,
t2.ICode
from table1 t1
left join table2 t2 on t1.ID = t2.ID;
您第一次加入的代码在哪里?让我们看看你试过什么?