不同列数的表可以用union吗?

来源:百度知道 编辑:UC知道 时间:2024/06/07 01:39:39
如何实现2张不同列数的表
t1
1,2
3,4
5,6

t2
a,b,c
d,e,f

结果集

1,2
3,4
5,6
a,b,c
d,e,f

使用union的前后两个查询语句的结构必须是一样的,可以采用字段组合或是不足补空行的方式把前后两个结构调整为一样的
如:
select col1,col2,'' as col3 from t1
union
select col1,col2,col3 from t2

将他们全部转换成字符串,添加空列,直到两个表的结构一样,就可以union了

select col1,col2,'' from t1
union
select col1,col2,col3 from t2;

agree with :lang_ren868

NO