如何将2个表的记录累计到一起?(50分)

lbl1005 2003-10-20 04:53:50
如何将2个表的记录累计到一起?
现在有2个表, 例如,表1有一个字段 f1, 有5条记录是 a,b,c,d,e,
表2有一个字段 f1, 有3条记录, h,k,l.
现在将此2个表的记录合在一起, 如下所示:
字段名是 : f3, 记录内容是 a,b,c,d,e,h,k,l.
在sql中就如何做到?使用sql语句
...全文
30 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dafu71 2003-10-20
  • 打赏
  • 举报
回复
Select f1 as f3 from table1
Union all
select f1 from table2
sdhdy 2003-10-20
  • 打赏
  • 举报
回复
declare @sql varchar(8000)
set @sql=''
select @sql=@sql+f3+',' from
(select f1 as f3 from 表1 where 你的条件 union all select f1 from 表2 where 你的条件) a
select left(@sql,len(@sql)-1) f3
zclxyh 2003-10-20
  • 打赏
  • 举报
回复
Select f1 as f3 from table1
Union all
select f1 from table2
ysycrazy 2003-10-20
  • 打赏
  • 举报
回复
Select f1 as f3 from 表1
Union all
select f1 from 表2
yujohny 2003-10-20
  • 打赏
  • 举报
回复
declare @str nvarchar(500)
set @str=''
select @str=@str+f3+',' from
(select f1 as f3 from 表1 Union all select f1 from 表2) A

select left(@str,len(@str)-1) as f3
伍子V5 2003-10-20
  • 打赏
  • 举报
回复
呵呵,可能是理解错了

Select f1 as f3 from table1
Union all
select f1 from table2
伍子V5 2003-10-20
  • 打赏
  • 举报
回复
select f1+f2 as f3 from table1 a,table2 b where 条件
zarge 2003-10-20
  • 打赏
  • 举报
回复
select f1 from 表1 union all select f3 from 表2
rocllllll 2003-10-20
  • 打赏
  • 举报
回复
select f1 from 表1 union select f1 from 表2
txlicenhe 2003-10-20
  • 打赏
  • 举报
回复
Select f1 as f3 from f1
Union all
select f1 from f2

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧