有2张mysql表表A:
name psw
n1 psw1
n2 psw2
n3 psw3 表B
psw sexpsw6 sex6
psw7 sex7
现在要把A和B合并成C, 有的字段就:
name psw sexn1 psw1 空
n2 psw2 空
n3 psw3 空
空 psw6 sex6
空 psw7 sex7
把2个表的字段都拿出来,去掉重复的,建立一张新表,然后把数据都填进去,没有的就为null(上面的'空')
name psw
n1 psw1
n2 psw2
n3 psw3 表B
psw sexpsw6 sex6
psw7 sex7
现在要把A和B合并成C, 有的字段就:
name psw sexn1 psw1 空
n2 psw2 空
n3 psw3 空
空 psw6 sex6
空 psw7 sex7
把2个表的字段都拿出来,去掉重复的,建立一张新表,然后把数据都填进去,没有的就为null(上面的'空')
from 表A
union all
select distinct null as name,psw ,sex
from 表B
from 表A
union
select null as name,psw ,sex
from 表B