为实现union,想为其中一个表添加一个字段 select ID, Name as visitername, date as visitedate, Avatar(多出的)
from tab1 union select ID, Name as visitername, CreateDate as visitedate from tab2 想在tab2里添加一个Avatar字段,类型是nvarchar(MAX),就相当于添加了一个和tab1里一样的字段:Avatar。并自动为填充“NULL”值 菜鸟,刚接触这些,问题比较多,之前的帖子还没结,现在有出现新的问题了。往CSDN里前辈指点指点晚辈呀。。
------解决方案--------------------
select ID, Name as visitername, date as visitedate, Avatar(多出的)
from tab1 union select ID, Name as visitername, CreateDate as visitedate, Null from tab2
------解决方案--------------------
------解决方案--------------------
SQL code
select
ID,Name as visitername,date as visitedate,Avatar
from tab1
union all --建议使用union all ,因为union把重复的去掉了。
select
ID,Name,CreateDate,null --多余的字段用null对应即可。(上面有as 别名了,下面不需要了)
from tab2